Comparing version 8.20.0 to 8.21.0
@@ -18,3 +18,2 @@ /** | ||
exports.defaultConfig = [ | ||
@@ -45,9 +44,5 @@ { | ||
}, | ||
ignores: [ | ||
"**/node_modules/**", | ||
".git/**" | ||
], | ||
languageOptions: { | ||
sourceType: "module", | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
parser: "@/espree", | ||
@@ -57,8 +52,22 @@ parserOptions: {} | ||
}, | ||
// default ignores are listed here | ||
{ | ||
ignores: [ | ||
"**/node_modules/**", | ||
".git/**" | ||
] | ||
}, | ||
// intentionally empty config to ensure these files are globbed by default | ||
{ | ||
files: ["**/*.js", "**/*.mjs"] | ||
}, | ||
{ | ||
files: ["**/*.cjs"], | ||
languageOptions: { | ||
sourceType: "commonjs" | ||
sourceType: "commonjs", | ||
ecmaVersion: "latest" | ||
} | ||
} | ||
]; |
@@ -39,2 +39,4 @@ /** | ||
const originalBaseConfig = Symbol("originalBaseConfig"); | ||
//----------------------------------------------------------------------------- | ||
@@ -52,6 +54,10 @@ // Exports | ||
* @param {*[]} configs An array of configuration information. | ||
* @param {{basePath: string, baseConfig: FlatConfig}} options The options | ||
* @param {{basePath: string, shouldIgnore: boolean, baseConfig: FlatConfig}} options The options | ||
* to use for the config array instance. | ||
*/ | ||
constructor(configs, { basePath, baseConfig = defaultConfig } = {}) { | ||
constructor(configs, { | ||
basePath, | ||
shouldIgnore = true, | ||
baseConfig = defaultConfig | ||
} = {}) { | ||
super(configs, { | ||
@@ -67,2 +73,18 @@ basePath, | ||
} | ||
/** | ||
* The baes config used to build the config array. | ||
* @type {Array<FlatConfig>} | ||
*/ | ||
this[originalBaseConfig] = baseConfig; | ||
Object.defineProperty(this, originalBaseConfig, { writable: false }); | ||
/** | ||
* Determines if `ignores` fields should be honored. | ||
* If true, then all `ignores` fields are honored. | ||
* if false, then only `ignores` fields in the baseConfig are honored. | ||
* @type {boolean} | ||
*/ | ||
this.shouldIgnore = shouldIgnore; | ||
Object.defineProperty(this, "shouldIgnore", { writable: false }); | ||
} | ||
@@ -93,2 +115,19 @@ | ||
/* | ||
* If `shouldIgnore` is false, we remove any ignore patterns specified | ||
* in the config so long as it's not a default config and it doesn't | ||
* have a `files` entry. | ||
*/ | ||
if ( | ||
!this.shouldIgnore && | ||
!this[originalBaseConfig].includes(config) && | ||
config.ignores && | ||
!config.files | ||
) { | ||
/* eslint-disable-next-line no-unused-vars -- need to strip off other keys */ | ||
const { ignores, ...otherKeys } = config; | ||
return otherKeys; | ||
} | ||
return config; | ||
@@ -95,0 +134,0 @@ } |
@@ -23,3 +23,10 @@ /** | ||
if (ruleId.includes("/")) { | ||
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/")); | ||
// mimic scoped npm packages | ||
if (ruleId.startsWith("@")) { | ||
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/")); | ||
} else { | ||
pluginName = ruleId.slice(0, ruleId.indexOf("/")); | ||
} | ||
ruleName = ruleId.slice(pluginName.length + 1); | ||
@@ -51,2 +58,3 @@ } else { | ||
// normalize function rules into objects | ||
@@ -53,0 +61,0 @@ if (rule && typeof rule === "function") { |
"use strict"; | ||
const { ESLint } = require("./eslint"); | ||
const { FlatESLint } = require("./flat-eslint"); | ||
module.exports = { | ||
ESLint | ||
ESLint, | ||
FlatESLint | ||
}; |
@@ -483,47 +483,50 @@ /** | ||
const baseConfig = { | ||
plugins: { | ||
const baseConfig = [ | ||
{ | ||
plugins: { | ||
// copy root plugin over | ||
"@": { | ||
// copy root plugin over | ||
"@": { | ||
/* | ||
* Parsers are wrapped to detect more errors, so this needs | ||
* to be a new object for each call to run(), otherwise the | ||
* parsers will be wrapped multiple times. | ||
*/ | ||
parsers: { | ||
...defaultConfig[0].plugins["@"].parsers | ||
/* | ||
* Parsers are wrapped to detect more errors, so this needs | ||
* to be a new object for each call to run(), otherwise the | ||
* parsers will be wrapped multiple times. | ||
*/ | ||
parsers: { | ||
...defaultConfig[0].plugins["@"].parsers | ||
}, | ||
/* | ||
* The rules key on the default plugin is a proxy to lazy-load | ||
* just the rules that are needed. So, don't create a new object | ||
* here, just use the default one to keep that performance | ||
* enhancement. | ||
*/ | ||
rules: defaultConfig[0].plugins["@"].rules | ||
}, | ||
"rule-to-test": { | ||
rules: { | ||
[ruleName]: Object.assign({}, rule, { | ||
/* | ||
* The rules key on the default plugin is a proxy to lazy-load | ||
* just the rules that are needed. So, don't create a new object | ||
* here, just use the default one to keep that performance | ||
* enhancement. | ||
*/ | ||
rules: defaultConfig[0].plugins["@"].rules | ||
}, | ||
"rule-to-test": { | ||
rules: { | ||
[ruleName]: Object.assign({}, rule, { | ||
// Create a wrapper rule that freezes the `context` properties. | ||
create(context) { | ||
freezeDeeply(context.options); | ||
freezeDeeply(context.settings); | ||
freezeDeeply(context.parserOptions); | ||
// Create a wrapper rule that freezes the `context` properties. | ||
create(context) { | ||
freezeDeeply(context.options); | ||
freezeDeeply(context.settings); | ||
freezeDeeply(context.parserOptions); | ||
// freezeDeeply(context.languageOptions); | ||
// freezeDeeply(context.languageOptions); | ||
return (typeof rule === "function" ? rule : rule.create)(context); | ||
} | ||
}) | ||
return (typeof rule === "function" ? rule : rule.create)(context); | ||
} | ||
}) | ||
} | ||
} | ||
}, | ||
languageOptions: { | ||
...defaultConfig[0].languageOptions | ||
} | ||
}, | ||
languageOptions: { | ||
...defaultConfig[0].languageOptions | ||
} | ||
}; | ||
...defaultConfig.slice(1) | ||
]; | ||
@@ -530,0 +533,0 @@ /** |
@@ -308,2 +308,32 @@ /** | ||
/** | ||
* Emit a deprecation warning if function-style format is being used. | ||
* @param {string} ruleName Name of the rule. | ||
* @returns {void} | ||
*/ | ||
function emitLegacyRuleAPIWarning(ruleName) { | ||
if (!emitLegacyRuleAPIWarning[`warned-${ruleName}`]) { | ||
emitLegacyRuleAPIWarning[`warned-${ruleName}`] = true; | ||
process.emitWarning( | ||
`"${ruleName}" rule is using the deprecated function-style format and will stop working in ESLint v9. Please use object-style format: https://eslint.org/docs/developer-guide/working-with-rules`, | ||
"DeprecationWarning" | ||
); | ||
} | ||
} | ||
/** | ||
* Emit a deprecation warning if rule has options but is missing the "meta.schema" property | ||
* @param {string} ruleName Name of the rule. | ||
* @returns {void} | ||
*/ | ||
function emitMissingSchemaWarning(ruleName) { | ||
if (!emitMissingSchemaWarning[`warned-${ruleName}`]) { | ||
emitMissingSchemaWarning[`warned-${ruleName}`] = true; | ||
process.emitWarning( | ||
`"${ruleName}" rule has options but is missing the "meta.schema" property and will stop working in ESLint v9. Please add a schema: https://eslint.org/docs/developer-guide/working-with-rules#options-schemas`, | ||
"DeprecationWarning" | ||
); | ||
} | ||
} | ||
//------------------------------------------------------------------------------ | ||
@@ -525,2 +555,5 @@ // Public Interface | ||
if (typeof rule === "function") { | ||
emitLegacyRuleAPIWarning(ruleName); | ||
} | ||
@@ -583,2 +616,11 @@ linter.defineRule(ruleName, Object.assign({}, rule, { | ||
assert(Array.isArray(item.options), "options must be an array"); | ||
if ( | ||
item.options.length > 0 && | ||
typeof rule === "object" && | ||
( | ||
!rule.meta || (rule.meta && (typeof rule.meta.schema === "undefined" || rule.meta.schema === null)) | ||
) | ||
) { | ||
emitMissingSchemaWarning(ruleName); | ||
} | ||
config.rules[ruleName] = [1].concat(item.options); | ||
@@ -585,0 +627,0 @@ } else { |
@@ -12,3 +12,6 @@ /** | ||
const astUtils = require("./utils/ast-utils"); | ||
const GraphemeSplitter = require("grapheme-splitter"); | ||
const splitter = new GraphemeSplitter(); | ||
//------------------------------------------------------------------------------ | ||
@@ -512,3 +515,3 @@ // Helpers | ||
return endToken.range[1] - startToken.range[0]; | ||
return splitter.countGraphemes(sourceCode.getText().slice(startToken.range[0], endToken.range[1])); | ||
} | ||
@@ -515,0 +518,0 @@ |
@@ -234,6 +234,12 @@ /** | ||
if (parent && isParentNodeType(parent, nodeType)) { | ||
const parentStartNodeOrToken = parent.type === "StaticBlock" | ||
? sourceCode.getFirstToken(parent, { skip: 1 }) // opening brace of the static block | ||
: parent; | ||
let parentStartNodeOrToken = parent; | ||
if (parent.type === "StaticBlock") { | ||
parentStartNodeOrToken = sourceCode.getFirstToken(parent, { skip: 1 }); // opening brace of the static block | ||
} else if (parent.type === "SwitchStatement") { | ||
parentStartNodeOrToken = sourceCode.getTokenAfter(parent.discriminant, { | ||
filter: astUtils.isOpeningBraceToken | ||
}); // opening brace of the switch statement | ||
} | ||
return token.loc.start.line - parentStartNodeOrToken.loc.start.line === 1; | ||
@@ -268,3 +274,4 @@ } | ||
isCommentAtParentStart(token, "StaticBlock") || | ||
isCommentAtParentStart(token, "SwitchCase") | ||
isCommentAtParentStart(token, "SwitchCase") || | ||
isCommentAtParentStart(token, "SwitchStatement") | ||
); | ||
@@ -271,0 +278,0 @@ } |
@@ -108,2 +108,6 @@ /** | ||
default: 2 | ||
}, | ||
allowLineSeparatedGroups: { | ||
type: "boolean", | ||
default: false | ||
} | ||
@@ -128,2 +132,3 @@ }, | ||
const minKeys = options && options.minKeys; | ||
const allowLineSeparatedGroups = options && options.allowLineSeparatedGroups || false; | ||
const isValidOrder = isValidOrders[ | ||
@@ -135,2 +140,3 @@ order + (insensitive ? "I" : "") + (natural ? "N" : "") | ||
let stack = null; | ||
const sourceCode = context.getSourceCode(); | ||
@@ -141,2 +147,4 @@ return { | ||
upper: stack, | ||
prevNode: null, | ||
prevBlankLine: false, | ||
prevName: null, | ||
@@ -166,2 +174,32 @@ numKeys: node.properties.length | ||
// Get tokens between current node and previous node | ||
const tokens = stack.prevNode && sourceCode | ||
.getTokensBetween(stack.prevNode, node, { includeComments: true }); | ||
let isBlankLineBetweenNodes = stack.prevBlankLine; | ||
if (tokens) { | ||
// check blank line between tokens | ||
tokens.forEach((token, index) => { | ||
const previousToken = tokens[index - 1]; | ||
if (previousToken && (token.loc.start.line - previousToken.loc.end.line > 1)) { | ||
isBlankLineBetweenNodes = true; | ||
} | ||
}); | ||
// check blank line between the current node and the last token | ||
if (!isBlankLineBetweenNodes && (node.loc.start.line - tokens[tokens.length - 1].loc.end.line > 1)) { | ||
isBlankLineBetweenNodes = true; | ||
} | ||
// check blank line between the first token and the previous node | ||
if (!isBlankLineBetweenNodes && (tokens[0].loc.start.line - stack.prevNode.loc.end.line > 1)) { | ||
isBlankLineBetweenNodes = true; | ||
} | ||
} | ||
stack.prevNode = node; | ||
if (thisName !== null) { | ||
@@ -171,2 +209,7 @@ stack.prevName = thisName; | ||
if (allowLineSeparatedGroups && isBlankLineBetweenNodes) { | ||
stack.prevBlankLine = thisName === null; | ||
return; | ||
} | ||
if (prevName === null || thisName === null || numKeys < minKeys) { | ||
@@ -173,0 +216,0 @@ return; |
@@ -15,2 +15,4 @@ /** | ||
const { FileEnumerator } = require("./cli-engine/file-enumerator"); | ||
const { FlatESLint } = require("./eslint/flat-eslint"); | ||
const FlatRuleTester = require("./rule-tester/flat-rule-tester"); | ||
@@ -23,3 +25,5 @@ //----------------------------------------------------------------------------- | ||
builtinRules: require("./rules"), | ||
FlatESLint, | ||
FlatRuleTester, | ||
FileEnumerator | ||
}; |
{ | ||
"name": "eslint", | ||
"version": "8.20.0", | ||
"version": "8.21.0", | ||
"author": "Nicholas C. Zakas <nicholas+npm@nczconsulting.com>", | ||
@@ -58,3 +58,4 @@ "description": "An AST-based pattern checker for JavaScript.", | ||
"@eslint/eslintrc": "^1.3.0", | ||
"@humanwhocodes/config-array": "^0.9.2", | ||
"@humanwhocodes/config-array": "^0.10.4", | ||
"@humanwhocodes/gitignore-to-minimatch": "^1.0.2", | ||
"ajv": "^6.10.0", | ||
@@ -69,3 +70,3 @@ "chalk": "^4.0.0", | ||
"eslint-visitor-keys": "^3.3.0", | ||
"espree": "^9.3.2", | ||
"espree": "^9.3.3", | ||
"esquery": "^1.4.0", | ||
@@ -75,5 +76,8 @@ "esutils": "^2.0.2", | ||
"file-entry-cache": "^6.0.1", | ||
"find-up": "^5.0.0", | ||
"functional-red-black-tree": "^1.0.1", | ||
"glob-parent": "^6.0.1", | ||
"globals": "^13.15.0", | ||
"globby": "^11.1.0", | ||
"grapheme-splitter": "^1.0.4", | ||
"ignore": "^5.2.0", | ||
@@ -111,3 +115,3 @@ "import-fresh": "^3.0.0", | ||
"eslint-plugin-jsdoc": "^38.1.6", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-n": "^15.2.4", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
@@ -148,3 +152,3 @@ "eslint-release": "^3.2.0", | ||
"proxyquire": "^2.0.1", | ||
"puppeteer": "^9.1.1", | ||
"puppeteer": "^13.7.0", | ||
"recast": "^0.20.4", | ||
@@ -151,0 +155,0 @@ "regenerator-runtime": "^0.13.2", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2794513
397
66438
39
16
+ Addedfind-up@^5.0.0
+ Addedglobby@^11.1.0
+ Addedgrapheme-splitter@^1.0.4
+ Added@humanwhocodes/config-array@0.10.7(transitive)
+ Added@humanwhocodes/gitignore-to-minimatch@1.0.2(transitive)
+ Added@nodelib/fs.scandir@2.1.5(transitive)
+ Added@nodelib/fs.stat@2.0.5(transitive)
+ Added@nodelib/fs.walk@1.2.8(transitive)
+ Addedarray-union@2.1.0(transitive)
+ Addedbraces@3.0.3(transitive)
+ Addeddir-glob@3.0.1(transitive)
+ Addedfast-glob@3.3.2(transitive)
+ Addedfastq@1.17.1(transitive)
+ Addedfill-range@7.1.1(transitive)
+ Addedfind-up@5.0.0(transitive)
+ Addedglob-parent@5.1.2(transitive)
+ Addedglobby@11.1.0(transitive)
+ Addedgrapheme-splitter@1.0.4(transitive)
+ Addedis-number@7.0.0(transitive)
+ Addedlocate-path@6.0.0(transitive)
+ Addedmerge2@1.4.1(transitive)
+ Addedmicromatch@4.0.8(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedp-locate@5.0.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpath-type@4.0.0(transitive)
+ Addedpicomatch@2.3.1(transitive)
+ Addedqueue-microtask@1.2.3(transitive)
+ Addedreusify@1.0.4(transitive)
+ Addedrun-parallel@1.2.0(transitive)
+ Addedslash@3.0.0(transitive)
+ Addedto-regex-range@5.0.1(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removed@humanwhocodes/config-array@0.9.5(transitive)
Updatedespree@^9.3.3