Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update: Flat config support in Linter (refs #13481) * Update lib/linter/linter.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/linter/linter.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Clean up FlatConfigArray detection * Add back FlatConfigArray import * More flat config tests passing; originals failing * Finish languageOptions features * Make sure to recognize RuleTester-wrapped Espree * Move globals into local file * Normalize ecmaVersion to year on context.languageOptions * Clean up ecmaVersion normalization * Revert parserOptions.ecmaVersion behavior to original * Add more tests * Update defaults for flat config (refs #14588) * More tests passing * Fix wrong ecmaVersion conversion * Duplicated all tests for FlatConfig * Finish languageOptions tests * Settings tests working * Rule context tests working * Options tests working * Directives tests working * reportUnusedDisableDirectives tests working * All original tests passing * Add test to verify lazy loading of rules (fixes #14862) * Fix failing tests * Fix failing browser test * Fix ecmaVersion edge cases * Switch globalReturn to false if sourceType is module * Update Espree and eslint-scope to support sourceType:commonjs * Update lib/linter/linter.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Update lib/linter/linter.js Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> * Fix processors functionality * Update lib/shared/types.js Co-authored-by: Brandon Mills <btmills@users.noreply.github.com> * Update tests/lib/linter/linter.js Co-authored-by: Brandon Mills <btmills@users.noreply.github.com> * Update tests/lib/linter/linter.js Co-authored-by: Brandon Mills <btmills@users.noreply.github.com> * Update lib/linter/linter.js Co-authored-by: Brandon Mills <btmills@users.noreply.github.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> Co-authored-by: Brandon Mills <btmills@users.noreply.github.com>
- Loading branch information
1 parent
54deec5
commit 32ac37a
Showing
14 changed files
with
8,125 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.