node_modules/eslint/lib/linter/linter.js in immosquare-cleaner-0.1.22 vs node_modules/eslint/lib/linter/linter.js in immosquare-cleaner-0.1.23
- old
+ new
@@ -42,10 +42,11 @@
ruleReplacements = require("../../conf/replacements.json");
const { getRuleFromConfig } = require("../config/flat-config-helpers");
const { FlatConfigArray } = require("../config/flat-config-array");
const { RuleValidator } = require("../config/rule-validator");
const { assertIsRuleOptions, assertIsRuleSeverity } = require("../config/flat-config-schema");
+const { normalizeSeverityToString } = require("../shared/severity");
const debug = require("debug")("eslint:linter");
const MAX_AUTOFIX_PASSES = 10;
const DEFAULT_PARSER_NAME = "espree";
const DEFAULT_ECMA_VERSION = 5;
const commentParser = new ConfigCommentParser();
@@ -315,28 +316,10 @@
}
return result;
}
/**
- * Extract the directive and the justification from a given directive comment and trim them.
- * @param {string} value The comment text to extract.
- * @returns {{directivePart: string, justificationPart: string}} The extracted directive and justification.
- */
-function extractDirectiveComment(value) {
- const match = /\s-{2,}\s/u.exec(value);
-
- if (!match) {
- return { directivePart: value.trim(), justificationPart: "" };
- }
-
- const directive = value.slice(0, match.index).trim();
- const justification = value.slice(match.index + match[0].length).trim();
-
- return { directivePart: directive, justificationPart: justification };
-}
-
-/**
* Parses comments in file to extract file-specific config of rules, globals
* and environments and merges them with global config; also code blocks
* where reporting is disabled or enabled and merges them with reporting config.
* @param {SourceCode} sourceCode The SourceCode object to get comments from.
* @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules
@@ -353,11 +336,11 @@
const validator = new ConfigValidator({
builtInRules: Rules
});
sourceCode.getInlineConfigNodes().filter(token => token.type !== "Shebang").forEach(comment => {
- const { directivePart, justificationPart } = extractDirectiveComment(comment.value);
+ const { directivePart, justificationPart } = commentParser.extractDirectiveComment(comment.value);
const match = directivesPattern.exec(directivePart);
if (!match) {
return;
@@ -498,11 +481,11 @@
function getDirectiveCommentsForFlatConfig(sourceCode, ruleMapper) {
const problems = [];
const disableDirectives = [];
sourceCode.getInlineConfigNodes().filter(token => token.type !== "Shebang").forEach(comment => {
- const { directivePart, justificationPart } = extractDirectiveComment(comment.value);
+ const { directivePart, justificationPart } = commentParser.extractDirectiveComment(comment.value);
const match = directivesPattern.exec(directivePart);
if (!match) {
return;
@@ -618,11 +601,11 @@
while ((match = eslintEnvPattern.exec(text)) !== null) {
if (match[0].endsWith("*/")) {
retv = Object.assign(
retv || {},
- commentParser.parseListConfig(extractDirectiveComment(match[1]).directivePart)
+ commentParser.parseListConfig(commentParser.extractDirectiveComment(match[1]).directivePart)
);
}
}
return retv;
@@ -669,13 +652,15 @@
if (typeof reportUnusedDisableDirectives === "boolean") {
reportUnusedDisableDirectives = reportUnusedDisableDirectives ? "error" : "off";
}
if (typeof reportUnusedDisableDirectives !== "string") {
- reportUnusedDisableDirectives =
- linterOptions.reportUnusedDisableDirectives
- ? "warn" : "off";
+ if (typeof linterOptions.reportUnusedDisableDirectives === "boolean") {
+ reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives ? "warn" : "off";
+ } else {
+ reportUnusedDisableDirectives = linterOptions.reportUnusedDisableDirectives === void 0 ? "off" : normalizeSeverityToString(linterOptions.reportUnusedDisableDirectives);
+ }
}
return {
filename: normalizeFilename(providedOptions.filename || "<input>"),
allowInlineConfig: !ignoreInlineConfig,
@@ -1420,11 +1405,11 @@
* @returns {LintMessage[]} The results as an array of messages or an empty array if no messages.
*/
verify(textOrSourceCode, config, filenameOrOptions) {
debug("Verify");
- const { configType } = internalSlotsMap.get(this);
+ const { configType, cwd } = internalSlotsMap.get(this);
const options = typeof filenameOrOptions === "string"
? { filename: filenameOrOptions }
: filenameOrOptions || {};
@@ -1439,10 +1424,10 @@
* `FlatConfigArray` if it has a `getConfig()` method.
*/
let configArray = config;
if (!Array.isArray(config) || typeof config.getConfig !== "function") {
- configArray = new FlatConfigArray(config);
+ configArray = new FlatConfigArray(config, { basePath: cwd });
configArray.normalizeSync();
}
return this._distinguishSuppressedMessages(this._verifyWithFlatConfigArray(textOrSourceCode, configArray, options, true));
}