node_modules/eslint/lib/linter/linter.js in immosquare-cleaner-0.1.46 vs node_modules/eslint/lib/linter/linter.js in immosquare-cleaner-0.1.47
- old
+ new
@@ -16,23 +16,20 @@
evk = require("eslint-visitor-keys"),
espree = require("espree"),
merge = require("lodash.merge"),
pkg = require("../../package.json"),
{
- directivesPattern
- } = require("../shared/directives"),
- {
Legacy: {
ConfigOps,
ConfigValidator,
environments: BuiltInEnvironments
}
} = require("@eslint/eslintrc/universal"),
Traverser = require("../shared/traverser"),
{ SourceCode } = require("../languages/js/source-code"),
applyDisableDirectives = require("./apply-disable-directives"),
- ConfigCommentParser = require("./config-comment-parser"),
+ { ConfigCommentParser } = require("@eslint/plugin-kit"),
NodeEventGenerator = require("./node-event-generator"),
createReportTranslator = require("./report-translator"),
Rules = require("./rules"),
createEmitter = require("./safe-emitter"),
SourceCodeFixer = require("./source-code-fixer"),
@@ -54,10 +51,11 @@
const DEFAULT_ERROR_LOC = { start: { line: 1, column: 0 }, end: { line: 1, column: 1 } };
const parserSymbol = Symbol.for("eslint.RuleTester.parser");
const { LATEST_ECMA_VERSION } = require("../../conf/ecma-version");
const { VFile } = require("./vfile");
const { ParserService } = require("../services/parser-service");
+const { FileContext } = require("./file-context");
const STEP_KIND_VISIT = 1;
const STEP_KIND_CALL = 2;
//------------------------------------------------------------------------------
// Typedefs
@@ -332,11 +330,11 @@
const directiveRules = ruleIds.length ? ruleIds : [null];
const result = {
directives: [], // valid disable directives
directiveProblems: [] // problems in directives
};
- const parentDirective = { node, ruleIds };
+ const parentDirective = { node, value, ruleIds };
for (const ruleId of directiveRules) {
const loc = sourceCode.getLoc(node);
@@ -400,80 +398,83 @@
const validator = new ConfigValidator({
builtInRules: Rules
});
sourceCode.getInlineConfigNodes().filter(token => token.type !== "Shebang").forEach(comment => {
- const { directivePart, justificationPart } = commentParser.extractDirectiveComment(comment.value);
- const match = directivesPattern.exec(directivePart);
+ const directive = commentParser.parseDirective(comment.value);
- if (!match) {
+ if (!directive) {
return;
}
- const directiveText = match[1];
- const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(directiveText);
+ const {
+ label,
+ value,
+ justification: justificationPart
+ } = directive;
+
+ const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(label);
+
if (comment.type === "Line" && !lineCommentSupported) {
return;
}
const loc = sourceCode.getLoc(comment);
if (warnInlineConfig) {
- const kind = comment.type === "Block" ? `/*${directiveText}*/` : `//${directiveText}`;
+ const kind = comment.type === "Block" ? `/*${label}*/` : `//${label}`;
problems.push(createLintingProblem({
ruleId: null,
message: `'${kind}' has no effect because you have 'noInlineConfig' setting in ${warnInlineConfig}.`,
loc,
severity: 1
}));
return;
}
- if (directiveText === "eslint-disable-line" && loc.start.line !== loc.end.line) {
- const message = `${directiveText} comment should not span multiple lines.`;
+ if (label === "eslint-disable-line" && loc.start.line !== loc.end.line) {
+ const message = `${label} comment should not span multiple lines.`;
problems.push(createLintingProblem({
ruleId: null,
message,
loc
}));
return;
}
- const directiveValue = directivePart.slice(match.index + directiveText.length);
-
- switch (directiveText) {
+ switch (label) {
case "eslint-disable":
case "eslint-enable":
case "eslint-disable-next-line":
case "eslint-disable-line": {
- const directiveType = directiveText.slice("eslint-".length);
+ const directiveType = label.slice("eslint-".length);
const { directives, directiveProblems } = createDisableDirectives({
type: directiveType,
- value: directiveValue,
+ value,
justification: justificationPart,
node: comment
}, ruleMapper, jslang, sourceCode);
disableDirectives.push(...directives);
problems.push(...directiveProblems);
break;
}
case "exported":
- Object.assign(exportedVariables, commentParser.parseListConfig(directiveValue, comment));
+ Object.assign(exportedVariables, commentParser.parseListConfig(value));
break;
case "globals":
case "global":
- for (const [id, { value }] of Object.entries(commentParser.parseStringConfig(directiveValue, comment))) {
+ for (const [id, idSetting] of Object.entries(commentParser.parseStringConfig(value))) {
let normalizedValue;
try {
- normalizedValue = ConfigOps.normalizeConfigGlobal(value);
+ normalizedValue = ConfigOps.normalizeConfigGlobal(idSetting);
} catch (err) {
problems.push(createLintingProblem({
ruleId: null,
loc,
message: err.message
@@ -492,13 +493,13 @@
}
}
break;
case "eslint": {
- const parseResult = commentParser.parseJsonConfig(directiveValue);
+ const parseResult = commentParser.parseJSONLikeConfig(value);
- if (parseResult.success) {
+ if (parseResult.ok) {
Object.keys(parseResult.config).forEach(name => {
const rule = ruleMapper(name);
const ruleValue = parseResult.config[name];
if (!rule) {
@@ -711,11 +712,11 @@
while ((match = eslintEnvPattern.exec(text)) !== null) {
if (match[0].endsWith("*/")) {
retv = Object.assign(
retv || {},
- commentParser.parseListConfig(commentParser.extractDirectiveComment(match[1]).directivePart)
+ commentParser.parseListConfig(commentParser.parseDirective(match[0].slice(2, -2)).value)
);
}
}
return retv;
@@ -977,27 +978,21 @@
/*
* Create a frozen object with the ruleContext properties and methods that are shared by all rules.
* All rule contexts will inherit from this object. This avoids the performance penalty of copying all the
* properties once for each rule.
*/
- const sharedTraversalContext = Object.freeze(
- {
- getCwd: () => cwd,
- cwd,
- getFilename: () => filename,
- filename,
- getPhysicalFilename: () => physicalFilename || filename,
- physicalFilename: physicalFilename || filename,
- getSourceCode: () => sourceCode,
- sourceCode,
- parserOptions: {
- ...languageOptions.parserOptions
- },
- parserPath: parserName,
- languageOptions,
- settings
- }
- );
+ const sharedTraversalContext = new FileContext({
+ cwd,
+ filename,
+ physicalFilename: physicalFilename || filename,
+ sourceCode,
+ parserOptions: {
+ ...languageOptions.parserOptions
+ },
+ parserPath: parserName,
+ languageOptions,
+ settings
+ });
const lintingProblems = [];
Object.keys(configuredRules).forEach(ruleId => {
const severity = ConfigOps.getRuleSeverity(configuredRules[ruleId]);