Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/rules/consistent-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Teddy Katz
*/

import * as utils from '../utils.js';
import { getKeyName, getTestInfo } from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand Down Expand Up @@ -44,13 +44,13 @@ const rule = {

return {
Program(ast) {
utils.getTestInfo(context, ast).forEach((testRun) => {
getTestInfo(context, ast).forEach((testRun) => {
const readableCases = testRun.invalid.filter(
(testCase) => testCase.type === 'ObjectExpression',
);
const casesWithoutOutput = readableCases.filter(
(testCase) =>
!testCase.properties.map(utils.getKeyName).includes('output'),
!testCase.properties.map(getKeyName).includes('output'),
);

if (
Expand Down
24 changes: 12 additions & 12 deletions lib/rules/fixer-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* @author 薛定谔的猫<[email protected]>
*/

// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------

import * as utils from '../utils.js';
import { getStaticValue } from '@eslint-community/eslint-utils';

import {
getContextIdentifiers,
isAutoFixerFunction,
isSuggestionFixerFunction,
} from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
// ------------------------------------------------------------------------------
Expand Down Expand Up @@ -70,15 +71,14 @@ const rule = {
* Check if a returned/yielded node is likely to be a fix or not.
* A fix is an object created by fixer.replaceText() for example and returned by the fix function.
* @param {ASTNode} node - node to check
* @param {Context} context
* @returns {boolean}
*/
function isFix(node) {
if (node.type === 'ArrayExpression' && node.elements.length === 0) {
// An empty array is not a fix.
return false;
}
const scope = utils.getScope(context);
const scope = context.sourceCode.getScope(node);
const staticValue = getStaticValue(node, scope);
if (!staticValue) {
// If we can't find a static value, assume it's a real fix value.
Expand All @@ -96,8 +96,8 @@ const rule = {

return {
Program(ast) {
const sourceCode = utils.getSourceCode(context);
contextIdentifiers = utils.getContextIdentifiers(
const sourceCode = context.sourceCode;
contextIdentifiers = getContextIdentifiers(
sourceCode.scopeManager,
ast,
);
Expand All @@ -111,8 +111,8 @@ const rule = {
hasYieldWithFixer: false,
hasReturnWithFixer: false,
shouldCheck:
utils.isAutoFixerFunction(node, contextIdentifiers) ||
utils.isSuggestionFixerFunction(node, contextIdentifiers),
isAutoFixerFunction(node, contextIdentifiers) ||
isSuggestionFixerFunction(node, contextIdentifiers),
node,
};
},
Expand Down Expand Up @@ -146,7 +146,7 @@ const rule = {
// Ensure the current (arrow) fixer function returned a fix.
'ArrowFunctionExpression:exit'(node) {
if (funcInfo.shouldCheck) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;
const loc = sourceCode.getTokenBefore(node.body).loc; // Show violation on arrow (=>).
if (node.expression) {
// When the return is implied (no curly braces around the body), we have to check the single body node directly.
Expand Down
6 changes: 2 additions & 4 deletions lib/rules/meta-property-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
* @fileoverview Enforces the order of meta properties
*/

import * as utils from '../utils.js';

const { getKeyName, getRuleInfo } = utils;
import { getKeyName, getRuleInfo } from '../utils.js';

const defaultOrder = [
'type',
Expand Down Expand Up @@ -48,7 +46,7 @@ const rule = {
},

create(context) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;
const ruleInfo = getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-deprecated-context-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Teddy Katz
*/

import * as utils from '../utils.js';
import { getContextIdentifiers } from '../utils.js';

const DEPRECATED_PASSTHROUGHS = {
getSource: 'getText',
Expand Down Expand Up @@ -52,15 +52,15 @@ const rule = {
},

create(context) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;

// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------

return {
'Program:exit'(ast) {
[...utils.getContextIdentifiers(sourceCode.scopeManager, ast)]
[...getContextIdentifiers(sourceCode.scopeManager, ast)]
.filter(
(contextId) =>
contextId.parent.type === 'MemberExpression' &&
Expand Down
8 changes: 4 additions & 4 deletions lib/rules/no-deprecated-report-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Teddy Katz
*/

import * as utils from '../utils.js';
import { getContextIdentifiers, getReportInfo } from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -28,7 +28,7 @@ const rule = {
},

create(context) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;
let contextIdentifiers;

// ----------------------------------------------------------------------
Expand All @@ -37,7 +37,7 @@ const rule = {

return {
Program(ast) {
contextIdentifiers = utils.getContextIdentifiers(
contextIdentifiers = getContextIdentifiers(
sourceCode.scopeManager,
ast,
);
Expand All @@ -58,7 +58,7 @@ const rule = {
fix(fixer) {
const openingParen = sourceCode.getTokenBefore(node.arguments[0]);
const closingParen = sourceCode.getLastToken(node);
const reportInfo = utils.getReportInfo(node, context);
const reportInfo = getReportInfo(node, context);

if (!reportInfo) {
return null;
Expand Down
6 changes: 3 additions & 3 deletions lib/rules/no-identical-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author 薛定谔的猫<[email protected]>
*/

import * as utils from '../utils.js';
import { getTestInfo } from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -30,7 +30,7 @@ const rule = {
// ----------------------------------------------------------------------
// Public
// ----------------------------------------------------------------------
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;

// ----------------------------------------------------------------------
// Helpers
Expand All @@ -52,7 +52,7 @@ const rule = {

return {
Program(ast) {
utils.getTestInfo(context, ast).forEach((testRun) => {
getTestInfo(context, ast).forEach((testRun) => {
[testRun.valid, testRun.invalid].forEach((tests) => {
const cache = new Set();
tests.forEach((test) => {
Expand Down
16 changes: 7 additions & 9 deletions lib/rules/no-meta-replaced-by.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @fileoverview Disallows the usage of `meta.replacedBy` property
*/

import * as utils from '../utils.js';
import { evaluateObjectProperties, getKeyName, getRuleInfo } from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -25,8 +25,8 @@ const rule = {
},
},
create(context) {
const sourceCode = utils.getSourceCode(context);
const ruleInfo = utils.getRuleInfo(sourceCode);
const sourceCode = context.sourceCode;
const ruleInfo = getRuleInfo(sourceCode);

if (!ruleInfo) {
return {};
Expand All @@ -40,12 +40,10 @@ const rule = {
return;
}

const replacedByNode = utils
.evaluateObjectProperties(metaNode, sourceCode.scopeManager)
.find(
(p) =>
p.type === 'Property' && utils.getKeyName(p) === 'replacedBy',
);
const replacedByNode = evaluateObjectProperties(
metaNode,
sourceCode.scopeManager,
).find((p) => p.type === 'Property' && getKeyName(p) === 'replacedBy');

if (!replacedByNode) {
return;
Expand Down
18 changes: 10 additions & 8 deletions lib/rules/no-meta-schema-default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { getStaticValue } from '@eslint-community/eslint-utils';
import * as utils from '../utils.js';

import {
getMetaSchemaNode,
getMetaSchemaNodeProperty,
getRuleInfo,
} from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -23,22 +28,19 @@ const rule = {
},

create(context) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
const ruleInfo = getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
}

const schemaNode = utils.getMetaSchemaNode(ruleInfo.meta, scopeManager);
const schemaNode = getMetaSchemaNode(ruleInfo.meta, scopeManager);
if (!schemaNode) {
return {};
}

const schemaProperty = utils.getMetaSchemaNodeProperty(
schemaNode,
scopeManager,
);
const schemaProperty = getMetaSchemaNodeProperty(schemaNode, scopeManager);

if (schemaProperty?.type === 'ObjectExpression') {
checkSchemaElement(schemaProperty, true);
Expand Down
33 changes: 18 additions & 15 deletions lib/rules/no-missing-message-ids.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import * as utils from '../utils.js';
import {
collectReportViolationAndSuggestionData,
findPossibleVariableValues,
getContextIdentifiers,
getMessagesNode,
getMessageIdNodeById,
getReportInfo,
getRuleInfo,
} from '../utils.js';

// ------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -24,14 +32,14 @@ const rule = {
},

create(context) {
const sourceCode = utils.getSourceCode(context);
const sourceCode = context.sourceCode;
const { scopeManager } = sourceCode;
const ruleInfo = utils.getRuleInfo(sourceCode);
const ruleInfo = getRuleInfo(sourceCode);
if (!ruleInfo) {
return {};
}

const messagesNode = utils.getMessagesNode(ruleInfo, scopeManager);
const messagesNode = getMessagesNode(ruleInfo, scopeManager);

let contextIdentifiers;

Expand All @@ -42,45 +50,40 @@ const rule = {

return {
Program(ast) {
contextIdentifiers = utils.getContextIdentifiers(scopeManager, ast);
contextIdentifiers = getContextIdentifiers(scopeManager, ast);
},

CallExpression(node) {
const scope = utils.getScope(context);
const scope = sourceCode.getScope(node);
// Check for messageId properties used in known calls to context.report();
if (
node.callee.type === 'MemberExpression' &&
contextIdentifiers.has(node.callee.object) &&
node.callee.property.type === 'Identifier' &&
node.callee.property.name === 'report'
) {
const reportInfo = utils.getReportInfo(node, context);
const reportInfo = getReportInfo(node, context);
if (!reportInfo) {
return;
}

const reportMessagesAndDataArray =
utils.collectReportViolationAndSuggestionData(reportInfo);
collectReportViolationAndSuggestionData(reportInfo);
for (const { messageId } of reportMessagesAndDataArray.filter(
(obj) => obj.messageId,
)) {
const values =
messageId.type === 'Literal'
? [messageId]
: utils.findPossibleVariableValues(messageId, scopeManager);
: findPossibleVariableValues(messageId, scopeManager);

// Look for any possible string values we found for this messageId.
values.forEach((val) => {
if (
val.type === 'Literal' &&
typeof val.value === 'string' &&
val.value !== '' &&
!utils.getMessageIdNodeById(
val.value,
ruleInfo,
scopeManager,
scope,
)
!getMessageIdNodeById(val.value, ruleInfo, scopeManager, scope)
)
// Couldn't find this messageId in `meta.messages`.
context.report({
Expand Down
Loading