New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Flat config support in Linter (refs #13481) #15185
Changes from 33 commits
a9da57b
a29a557
38c0d16
f2a7458
66cf8a3
dfdd4fa
531be0c
e3e9367
4ffbc2e
3bc4832
8076425
a20e642
cee5632
ac3f270
7a03b48
e948144
703e590
360c2d7
aaab04e
f25b139
f6ea3f7
c0a1eb4
f6b1207
90c3214
7130a27
165e59b
2536a6b
e0e1618
240f0ad
a351eec
4cd44a4
8cffdc8
2c2e5d7
d40a473
78237f2
b042303
9ad40d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* @fileoverview Globals for ecmaVersion/sourceType | ||
* @author Nicholas C. Zakas | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//----------------------------------------------------------------------------- | ||
// Globals | ||
//----------------------------------------------------------------------------- | ||
|
||
const commonjs = { | ||
exports: true, | ||
global: false, | ||
module: false, | ||
require: false | ||
}; | ||
|
||
const es3 = { | ||
Array: false, | ||
Boolean: false, | ||
constructor: false, | ||
Date: false, | ||
decodeURI: false, | ||
decodeURIComponent: false, | ||
encodeURI: false, | ||
encodeURIComponent: false, | ||
Error: false, | ||
escape: false, | ||
eval: false, | ||
EvalError: false, | ||
Function: false, | ||
hasOwnProperty: false, | ||
Infinity: false, | ||
isFinite: false, | ||
isNaN: false, | ||
isPrototypeOf: false, | ||
Math: false, | ||
NaN: false, | ||
Number: false, | ||
Object: false, | ||
parseFloat: false, | ||
parseInt: false, | ||
propertyIsEnumerable: false, | ||
RangeError: false, | ||
ReferenceError: false, | ||
RegExp: false, | ||
String: false, | ||
SyntaxError: false, | ||
toLocaleString: false, | ||
toString: false, | ||
TypeError: false, | ||
undefined: false, | ||
unescape: false, | ||
URIError: false, | ||
valueOf: false | ||
}; | ||
|
||
const es5 = { | ||
...es3, | ||
JSON: false | ||
}; | ||
|
||
const es2015 = { | ||
...es5, | ||
ArrayBuffer: false, | ||
DataView: false, | ||
Float32Array: false, | ||
Float64Array: false, | ||
Int16Array: false, | ||
Int32Array: false, | ||
Int8Array: false, | ||
Map: false, | ||
Promise: false, | ||
Proxy: false, | ||
Reflect: false, | ||
Set: false, | ||
Symbol: false, | ||
Uint16Array: false, | ||
Uint32Array: false, | ||
Uint8Array: false, | ||
Uint8ClampedArray: false, | ||
WeakMap: false, | ||
WeakSet: false | ||
}; | ||
|
||
// no new globals in ES2016 | ||
const es2016 = { | ||
...es2015 | ||
}; | ||
|
||
const es2017 = { | ||
...es2016, | ||
Atomics: false, | ||
SharedArrayBuffer: false | ||
}; | ||
|
||
// no new globals in ES2018 | ||
const es2018 = { | ||
...es2017 | ||
}; | ||
|
||
// no new globals in ES2019 | ||
const es2019 = { | ||
...es2018 | ||
}; | ||
|
||
const es2020 = { | ||
...es2019, | ||
BigInt: false, | ||
BigInt64Array: false, | ||
BigUint64Array: false, | ||
globalThis: false | ||
}; | ||
|
||
const es2021 = { | ||
...es2020, | ||
AggregateError: false, | ||
FinalizationRegistry: false, | ||
WeakRef: false | ||
}; | ||
|
||
const es2022 = { | ||
...es2021 | ||
}; | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
// Exports | ||
//----------------------------------------------------------------------------- | ||
|
||
module.exports = { | ||
commonjs, | ||
es3, | ||
es5, | ||
es2015, | ||
es2016, | ||
es2017, | ||
es2018, | ||
es2019, | ||
es2020, | ||
es2021, | ||
es2022 | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ exports.defaultConfig = [ | |
|
||
/* | ||
* Because we try to delay loading rules until absolutely | ||
* necessary, a proxy allows us to hook into the lazy-loading | ||
* necessary, a proxy allows us to hook into the lazy-loading | ||
* aspect of the rules map while still keeping all of the | ||
* relevant configuration inside of the config array. | ||
*/ | ||
|
@@ -46,7 +46,16 @@ exports.defaultConfig = [ | |
".git/**" | ||
], | ||
languageOptions: { | ||
parser: "@/espree" | ||
ecmaVersion: "latest", | ||
sourceType: "module", | ||
parser: "@/espree", | ||
parserOptions: {} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating the defaults as briefly discussed in #14588. I think it makes sense to assume people will be using ESM and always want the latest |
||
}, | ||
{ | ||
files: ["**/*.cjs"], | ||
languageOptions: { | ||
sourceType: "commonjs" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
} | ||
} | ||
]; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @fileoverview Shared functions to work with configs. | ||
* @author Nicholas C. Zakas | ||
*/ | ||
|
||
"use strict"; | ||
|
||
//----------------------------------------------------------------------------- | ||
// Functions | ||
//----------------------------------------------------------------------------- | ||
|
||
/** | ||
* Parses a ruleId into its plugin and rule parts. | ||
* @param {string} ruleId The rule ID to parse. | ||
* @returns {{pluginName:string,ruleName:string}} The plugin and rule | ||
* parts of the ruleId; | ||
*/ | ||
function parseRuleId(ruleId) { | ||
let pluginName, ruleName; | ||
|
||
// distinguish between core rules and plugin rules | ||
if (ruleId.includes("/")) { | ||
pluginName = ruleId.slice(0, ruleId.lastIndexOf("/")); | ||
ruleName = ruleId.slice(pluginName.length + 1); | ||
} else { | ||
pluginName = "@"; | ||
ruleName = ruleId; | ||
} | ||
|
||
return { | ||
pluginName, | ||
ruleName | ||
}; | ||
} | ||
|
||
/** | ||
* Retrieves a rule instance from a given config based on the ruleId. | ||
* @param {string} ruleId The rule ID to look for. | ||
* @param {FlatConfig} config The config to search. | ||
* @returns {import("../shared/types").Rule|undefined} The rule if found | ||
* or undefined if not. | ||
*/ | ||
function getRuleFromConfig(ruleId, config) { | ||
|
||
const { pluginName, ruleName } = parseRuleId(ruleId); | ||
|
||
const plugin = config.plugins && config.plugins[pluginName]; | ||
let rule = plugin && plugin.rules && plugin.rules[ruleName]; | ||
|
||
// normalize function rules into objects | ||
if (rule && typeof rule === "function") { | ||
rule = { | ||
create: rule | ||
}; | ||
} | ||
|
||
return rule; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Exports | ||
//----------------------------------------------------------------------------- | ||
|
||
module.exports = { | ||
parseRuleId, | ||
getRuleFromConfig | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved globals here since the list is much smaller without environments, allowing us to update more easily and also support ES3 correctly (right now we still add
JSON
whenecmaVersion
is 3.