diff --git a/docs/src/extend/code-path-analysis.md b/docs/src/extend/code-path-analysis.md index 424f7163c50..7344f8647ad 100644 --- a/docs/src/extend/code-path-analysis.md +++ b/docs/src/extend/code-path-analysis.md @@ -259,7 +259,7 @@ Please use a map of information instead. ```js function hasCb(node, context) { if (node.type.indexOf("Function") !== -1) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return sourceCode.getDeclaredVariables(node).some(function(v) { return v.type === "Parameter" && v.name === "cb"; }); diff --git a/docs/src/extend/custom-rules.md b/docs/src/extend/custom-rules.md index 6d69f1a4a67..35b04fdbf8e 100644 --- a/docs/src/extend/custom-rules.md +++ b/docs/src/extend/custom-rules.md @@ -128,6 +128,7 @@ The `context` object has the following properties: * `physicalFilename`: (`string`) When linting a file, it provides the full path of the file on disk without any code block information. When linting text, it provides the value passed to `—stdin-filename` or `` if not specified. * `cwd`: (`string`) The `cwd` option passed to the [Linter](../integrate/nodejs-api#linter). It is a path to a directory that should be considered the current working directory. * `options`: (`array`) An array of the [configured options](../use/configure/rules) for this rule. This array does not include the rule severity (see the [dedicated section](#accessing-options-passed-to-a-rule)). +* `sourceCode`: (`object`) A `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)). * `settings`: (`object`) The [shared settings](../use/configure/configuration-files#adding-shared-settings) from the configuration. * `parserPath`: (`string`) The name of the `parser` from the configuration. * `parserServices`: (`object`) Contains parser-provided services for rules. The default parser does not provide any services. However, if a rule is intended to be used with a custom parser, it could use `parserServices` to access anything provided by that parser. (For example, a TypeScript parser could provide the ability to get the computed type of a given node.) @@ -150,7 +151,7 @@ Additionally, the `context` object has the following methods: * `getFilename()`: (**Deprecated:** Use `context.filename` instead.) Returns the filename associated with the source. * `getPhysicalFilename()`: (**Deprecated:** Use `context.physicalFilename` instead.) When linting a file, it returns the full path of the file on disk without any code block information. When linting text, it returns the value passed to `—stdin-filename` or `` if not specified. * `getScope()`: (**Deprecated:** Use `SourceCode#getScope(node)` instead.) Returns the [scope](./scope-manager-interface#scope-interface) of the currently-traversed node. This information can be used to track references to variables. -* `getSourceCode()`: Returns a `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)). +* `getSourceCode()`: (**Deprecated:** Use `context.sourceCode` instead.) Returns a `SourceCode` object that you can use to work with the source that was passed to ESLint (see [Accessing the Source Code](#accessing-the-source-code)). * `markVariableAsUsed(name)`: (**Deprecated:** Use `SourceCode#markVariableAsUsed(name, node)` instead.) Marks a variable with the given name in the current scope as used. This affects the [no-unused-vars](../rules/no-unused-vars) rule. Returns `true` if a variable with the given name was found and marked as used, otherwise `false`. * `report(descriptor)`. Reports a problem in the code (see the [dedicated section](#reporting-problems)). @@ -509,18 +510,20 @@ When using options, make sure that your rule has some logical defaults in case t ### Accessing the Source Code -The `SourceCode` object is the main object for getting more information about the source code being linted. You can retrieve the `SourceCode` object at any time by using the `context.getSourceCode()` method: +The `SourceCode` object is the main object for getting more information about the source code being linted. You can retrieve the `SourceCode` object at any time by using the `context.sourceCode` property: ```js module.exports = { create: function(context) { - var sourceCode = context.getSourceCode(); + var sourceCode = context.sourceCode; // ... } }; ``` +**Deprecated:** The `context.getSourceCode()` method is deprecated; make sure to use `context.sourceCode` property instead. + Once you have an instance of `SourceCode`, you can use the following methods on it to work with the code: * `getText(node)`: Returns the source code for the given node. Omit `node` to get the whole source (see the [dedicated section](#accessing-the-source-text)). @@ -712,7 +715,7 @@ To help with this, you can use the `sourceCode.markVariableAsUsed()` method. Thi ```js module.exports = { create: function(context) { - var sourceCode = context.getSourceCode(); + var sourceCode = context.sourceCode; return { ReturnStatement(node) { diff --git a/lib/linter/linter.js b/lib/linter/linter.js index c3ff7bbe455..ff8395d2601 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -902,7 +902,7 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze( (contextInfo, methodName) => Object.assign(contextInfo, { [methodName](...args) { - return this.getSourceCode()[DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]](...args); + return this.sourceCode[DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]](...args); } }), {} @@ -958,6 +958,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserName, languageO physicalFilename: physicalFilename || filename, getScope: () => sourceCode.getScope(currentNode), getSourceCode: () => sourceCode, + sourceCode, markVariableAsUsed: name => sourceCode.markVariableAsUsed(name, currentNode), parserOptions: { ...languageOptions.parserOptions diff --git a/lib/rules/accessor-pairs.js b/lib/rules/accessor-pairs.js index a456df5c843..03b51e461c0 100644 --- a/lib/rules/accessor-pairs.js +++ b/lib/rules/accessor-pairs.js @@ -178,7 +178,7 @@ module.exports = { const checkGetWithoutSet = config.getWithoutSet === true; const checkSetWithoutGet = config.setWithoutGet !== false; const enforceForClassMembers = config.enforceForClassMembers !== false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports the given node. diff --git a/lib/rules/array-bracket-newline.js b/lib/rules/array-bracket-newline.js index acd9c48cf25..c3676bf4dfa 100644 --- a/lib/rules/array-bracket-newline.js +++ b/lib/rules/array-bracket-newline.js @@ -56,7 +56,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- diff --git a/lib/rules/array-bracket-spacing.js b/lib/rules/array-bracket-spacing.js index 565a39a8560..e3a46d82214 100644 --- a/lib/rules/array-bracket-spacing.js +++ b/lib/rules/array-bracket-spacing.js @@ -53,7 +53,7 @@ module.exports = { }, create(context) { const spaced = context.options[0] === "always", - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; /** * Determines whether an option is set, relative to the spacing option. diff --git a/lib/rules/array-callback-return.js b/lib/rules/array-callback-return.js index 39912ec0a10..05cd4ede966 100644 --- a/lib/rules/array-callback-return.js +++ b/lib/rules/array-callback-return.js @@ -172,7 +172,7 @@ module.exports = { create(context) { const options = context.options[0] || { allowImplicit: false, checkForEach: false }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let funcInfo = { arrayMethodName: null, diff --git a/lib/rules/array-element-newline.js b/lib/rules/array-element-newline.js index e2635513138..be547ec3617 100644 --- a/lib/rules/array-element-newline.js +++ b/lib/rules/array-element-newline.js @@ -79,7 +79,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/arrow-body-style.js b/lib/rules/arrow-body-style.js index b305c8c5fe7..759070454c4 100644 --- a/lib/rules/arrow-body-style.js +++ b/lib/rules/arrow-body-style.js @@ -74,7 +74,7 @@ module.exports = { const asNeeded = !options[0] || options[0] === "as-needed"; const never = options[0] === "never"; const requireReturnForObjectLiteral = options[1] && options[1].requireReturnForObjectLiteral; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let funcInfo = null; /** diff --git a/lib/rules/arrow-parens.js b/lib/rules/arrow-parens.js index c4f73da223c..0463323176e 100644 --- a/lib/rules/arrow-parens.js +++ b/lib/rules/arrow-parens.js @@ -69,7 +69,7 @@ module.exports = { const asNeeded = context.options[0] === "as-needed"; const requireForBlockBody = asNeeded && context.options[1] && context.options[1].requireForBlockBody === true; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Finds opening paren of parameters for the given arrow function, if it exists. diff --git a/lib/rules/arrow-spacing.js b/lib/rules/arrow-spacing.js index ef2a0efbb2e..fb74d2cb272 100644 --- a/lib/rules/arrow-spacing.js +++ b/lib/rules/arrow-spacing.js @@ -61,7 +61,7 @@ module.exports = { rule.before = rule.before !== false; rule.after = rule.after !== false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Get tokens of arrow(`=>`) and before/after arrow. diff --git a/lib/rules/block-scoped-var.js b/lib/rules/block-scoped-var.js index 213ee5edbb8..5a951276c59 100644 --- a/lib/rules/block-scoped-var.js +++ b/lib/rules/block-scoped-var.js @@ -28,7 +28,7 @@ module.exports = { create(context) { let stack = []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Makes a block scope. diff --git a/lib/rules/block-spacing.js b/lib/rules/block-spacing.js index 01dd8f92f4e..dd4851c6843 100644 --- a/lib/rules/block-spacing.js +++ b/lib/rules/block-spacing.js @@ -37,7 +37,7 @@ module.exports = { create(context) { const always = (context.options[0] !== "never"), messageId = always ? "missing" : "extra", - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; /** * Gets the open brace token from a given node. diff --git a/lib/rules/brace-style.js b/lib/rules/brace-style.js index 2c14e7051c9..59758c90925 100644 --- a/lib/rules/brace-style.js +++ b/lib/rules/brace-style.js @@ -53,7 +53,7 @@ module.exports = { create(context) { const style = context.options[0] || "1tbs", params = context.options[1] || {}, - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/callback-return.js b/lib/rules/callback-return.js index b91e9d4b524..5d441bdd9fa 100644 --- a/lib/rules/callback-return.js +++ b/lib/rules/callback-return.js @@ -37,7 +37,7 @@ module.exports = { create(context) { const callbacks = context.options[0] || ["callback", "cb", "next"], - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/camelcase.js b/lib/rules/camelcase.js index 0c1a35b0a0e..51bb4122df0 100644 --- a/lib/rules/camelcase.js +++ b/lib/rules/camelcase.js @@ -73,7 +73,7 @@ module.exports = { const ignoreImports = options.ignoreImports; const ignoreGlobals = options.ignoreGlobals; const allow = options.allow || []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/capitalized-comments.js b/lib/rules/capitalized-comments.js index 2324062d01d..3a17b056620 100644 --- a/lib/rules/capitalized-comments.js +++ b/lib/rules/capitalized-comments.js @@ -139,7 +139,7 @@ module.exports = { const capitalize = context.options[0] || "always", normalizedOptions = getAllNormalizedOptions(context.options[1]), - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; createRegExpForIgnorePatterns(normalizedOptions); diff --git a/lib/rules/class-methods-use-this.js b/lib/rules/class-methods-use-this.js index 052d62825b8..9cf8a1b8a86 100644 --- a/lib/rules/class-methods-use-this.js +++ b/lib/rules/class-methods-use-this.js @@ -133,7 +133,7 @@ module.exports = { if (isIncludedInstanceMethod(node.parent) && !methodUsesThis) { context.report({ node, - loc: astUtils.getFunctionHeadLoc(node, context.getSourceCode()), + loc: astUtils.getFunctionHeadLoc(node, context.sourceCode), messageId: "missingThis", data: { name: astUtils.getFunctionNameWithKind(node) diff --git a/lib/rules/comma-dangle.js b/lib/rules/comma-dangle.js index d39ff1a66b3..e49983b722e 100644 --- a/lib/rules/comma-dangle.js +++ b/lib/rules/comma-dangle.js @@ -136,7 +136,7 @@ module.exports = { create(context) { const options = normalizeOptions(context.options[0], context.languageOptions.ecmaVersion); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Gets the last item of the given node. diff --git a/lib/rules/comma-spacing.js b/lib/rules/comma-spacing.js index 206bbd50abe..96015ef6779 100644 --- a/lib/rules/comma-spacing.js +++ b/lib/rules/comma-spacing.js @@ -48,7 +48,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const tokensAndComments = sourceCode.tokensAndComments; const options = { diff --git a/lib/rules/comma-style.js b/lib/rules/comma-style.js index a267e86473d..bc69de4698d 100644 --- a/lib/rules/comma-style.js +++ b/lib/rules/comma-style.js @@ -51,7 +51,7 @@ module.exports = { create(context) { const style = context.options[0] || "last", - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; const exceptions = { ArrayPattern: true, ArrowFunctionExpression: true, diff --git a/lib/rules/computed-property-spacing.js b/lib/rules/computed-property-spacing.js index a089922fcb8..1e4e17c6c71 100644 --- a/lib/rules/computed-property-spacing.js +++ b/lib/rules/computed-property-spacing.js @@ -49,7 +49,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const propertyNameMustBeSpaced = context.options[0] === "always"; // default is "never" const enforceForClassMembers = !context.options[1] || context.options[1].enforceForClassMembers; diff --git a/lib/rules/consistent-return.js b/lib/rules/consistent-return.js index 6ff2f8f5829..e2d3f078270 100644 --- a/lib/rules/consistent-return.js +++ b/lib/rules/consistent-return.js @@ -104,7 +104,7 @@ module.exports = { } else if (node.type === "ArrowFunctionExpression") { // `=>` token - loc = context.getSourceCode().getTokenBefore(node.body, astUtils.isArrowToken).loc; + loc = context.sourceCode.getTokenBefore(node.body, astUtils.isArrowToken).loc; } else if ( node.parent.type === "MethodDefinition" || (node.parent.type === "Property" && node.parent.method) @@ -115,7 +115,7 @@ module.exports = { } else { // Function name or `function` keyword. - loc = (node.id || context.getSourceCode().getFirstToken(node)).loc; + loc = (node.id || context.sourceCode.getFirstToken(node)).loc; } if (!name) { diff --git a/lib/rules/consistent-this.js b/lib/rules/consistent-this.js index a77d8c42171..658957ae25b 100644 --- a/lib/rules/consistent-this.js +++ b/lib/rules/consistent-this.js @@ -36,7 +36,7 @@ module.exports = { create(context) { let aliases = []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (context.options.length === 0) { aliases.push("that"); diff --git a/lib/rules/curly.js b/lib/rules/curly.js index ce24fd55220..35408247a19 100644 --- a/lib/rules/curly.js +++ b/lib/rules/curly.js @@ -70,7 +70,7 @@ module.exports = { const multiOrNest = (context.options[0] === "multi-or-nest"); const consistent = (context.options[1] === "consistent"); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/default-case.js b/lib/rules/default-case.js index c0e5d32ba83..4f2fad0c4f8 100644 --- a/lib/rules/default-case.js +++ b/lib/rules/default-case.js @@ -42,7 +42,7 @@ module.exports = { ? new RegExp(options.commentPattern, "u") : DEFAULT_COMMENT_PATTERN; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/dot-location.js b/lib/rules/dot-location.js index 2a2f2565e74..dac98b06b9e 100644 --- a/lib/rules/dot-location.js +++ b/lib/rules/dot-location.js @@ -43,7 +43,7 @@ module.exports = { // default to onObject if no preference is passed const onObject = config === "object" || !config; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports if the dot between object and property is on the correct location. diff --git a/lib/rules/dot-notation.js b/lib/rules/dot-notation.js index 54e316d074e..78f13686774 100644 --- a/lib/rules/dot-notation.js +++ b/lib/rules/dot-notation.js @@ -59,7 +59,7 @@ module.exports = { create(context) { const options = context.options[0] || {}; const allowKeywords = options.allowKeywords === void 0 || options.allowKeywords; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let allowPattern; diff --git a/lib/rules/eol-last.js b/lib/rules/eol-last.js index f698e0e36f5..1036db1a108 100644 --- a/lib/rules/eol-last.js +++ b/lib/rules/eol-last.js @@ -40,7 +40,7 @@ module.exports = { return { Program: function checkBadEOF(node) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, src = sourceCode.getText(), lastLine = sourceCode.lines[sourceCode.lines.length - 1], location = { diff --git a/lib/rules/eqeqeq.js b/lib/rules/eqeqeq.js index 3c5deb1907d..12b1e805ec1 100644 --- a/lib/rules/eqeqeq.js +++ b/lib/rules/eqeqeq.js @@ -68,7 +68,7 @@ module.exports = { create(context) { const config = context.options[0] || "always"; const options = context.options[1] || {}; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const nullOption = (config === "always") ? options.null || "always" diff --git a/lib/rules/func-call-spacing.js b/lib/rules/func-call-spacing.js index 11ecbe186af..3d5e538493e 100644 --- a/lib/rules/func-call-spacing.js +++ b/lib/rules/func-call-spacing.js @@ -73,7 +73,7 @@ module.exports = { const never = context.options[0] !== "always"; const allowNewlines = !never && context.options[1] && context.options[1].allowNewlines; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const text = sourceCode.getText(); /** diff --git a/lib/rules/func-names.js b/lib/rules/func-names.js index 23399d63ffc..b180580e114 100644 --- a/lib/rules/func-names.js +++ b/lib/rules/func-names.js @@ -69,7 +69,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Returns the config option for the given node. diff --git a/lib/rules/function-call-argument-newline.js b/lib/rules/function-call-argument-newline.js index 753e752daa2..4462afd0b7c 100644 --- a/lib/rules/function-call-argument-newline.js +++ b/lib/rules/function-call-argument-newline.js @@ -35,7 +35,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const checkers = { unexpected: { diff --git a/lib/rules/function-paren-newline.js b/lib/rules/function-paren-newline.js index 822db923601..8a8714ac95d 100644 --- a/lib/rules/function-paren-newline.js +++ b/lib/rules/function-paren-newline.js @@ -57,7 +57,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const rawOption = context.options[0] || "multiline"; const multilineOption = rawOption === "multiline"; const multilineArgumentsOption = rawOption === "multiline-arguments"; diff --git a/lib/rules/generator-star-spacing.js b/lib/rules/generator-star-spacing.js index 24aeb55ba8c..81c0b61059a 100644 --- a/lib/rules/generator-star-spacing.js +++ b/lib/rules/generator-star-spacing.js @@ -102,7 +102,7 @@ module.exports = { }; }(context.options[0] || {})); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks if the given token is a star token or not. diff --git a/lib/rules/getter-return.js b/lib/rules/getter-return.js index cb7f3a0fc69..622b6a7541c 100644 --- a/lib/rules/getter-return.js +++ b/lib/rules/getter-return.js @@ -64,7 +64,7 @@ module.exports = { create(context) { const options = context.options[0] || { allowImplicit: false }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let funcInfo = { upper: null, diff --git a/lib/rules/global-require.js b/lib/rules/global-require.js index be2d6f202c5..deae9d2676f 100644 --- a/lib/rules/global-require.js +++ b/lib/rules/global-require.js @@ -71,7 +71,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { diff --git a/lib/rules/grouped-accessor-pairs.js b/lib/rules/grouped-accessor-pairs.js index 4d857a409ed..c08e1c4973e 100644 --- a/lib/rules/grouped-accessor-pairs.js +++ b/lib/rules/grouped-accessor-pairs.js @@ -115,7 +115,7 @@ module.exports = { create(context) { const order = context.options[0] || "anyOrder"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports the given accessor pair. diff --git a/lib/rules/handle-callback-err.js b/lib/rules/handle-callback-err.js index 384243dcae1..ad84931a9ca 100644 --- a/lib/rules/handle-callback-err.js +++ b/lib/rules/handle-callback-err.js @@ -38,7 +38,7 @@ module.exports = { create(context) { const errorArgument = context.options[0] || "err"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks if the given argument should be interpreted as a regexp pattern. diff --git a/lib/rules/id-blacklist.js b/lib/rules/id-blacklist.js index adb004e1a71..6b7f561ee03 100644 --- a/lib/rules/id-blacklist.js +++ b/lib/rules/id-blacklist.js @@ -140,7 +140,7 @@ module.exports = { const denyList = new Set(context.options); const reportedNodes = new Set(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let globalScope; diff --git a/lib/rules/id-denylist.js b/lib/rules/id-denylist.js index e59137ad59d..baaa65fe01a 100644 --- a/lib/rules/id-denylist.js +++ b/lib/rules/id-denylist.js @@ -121,7 +121,7 @@ module.exports = { const denyList = new Set(context.options); const reportedNodes = new Set(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let globalScope; diff --git a/lib/rules/id-match.js b/lib/rules/id-match.js index b6ca8bd68c3..e225454e771 100644 --- a/lib/rules/id-match.js +++ b/lib/rules/id-match.js @@ -67,7 +67,7 @@ module.exports = { onlyDeclarations = !!options.onlyDeclarations, ignoreDestructuring = !!options.ignoreDestructuring; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let globalScope; //-------------------------------------------------------------------------- diff --git a/lib/rules/implicit-arrow-linebreak.js b/lib/rules/implicit-arrow-linebreak.js index 66556765102..30ab1a5f3d0 100644 --- a/lib/rules/implicit-arrow-linebreak.js +++ b/lib/rules/implicit-arrow-linebreak.js @@ -34,7 +34,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const option = context.options[0] || "beside"; /** diff --git a/lib/rules/indent-legacy.js b/lib/rules/indent-legacy.js index 2774bfe9508..78bf965cb3f 100644 --- a/lib/rules/indent-legacy.js +++ b/lib/rules/indent-legacy.js @@ -206,7 +206,7 @@ module.exports = { ObjectExpression: 1 }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (context.options.length) { if (context.options[0] === "tab") { diff --git a/lib/rules/indent.js b/lib/rules/indent.js index 61b5e9b40c9..25ec06cac28 100644 --- a/lib/rules/indent.js +++ b/lib/rules/indent.js @@ -703,7 +703,7 @@ module.exports = { } } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const tokenInfo = new TokenInfo(sourceCode); const offsets = new OffsetStorage(tokenInfo, indentSize, indentType === "space" ? " " : "\t"); const parameterParens = new WeakSet(); diff --git a/lib/rules/key-spacing.js b/lib/rules/key-spacing.js index adcd44c5298..0b51eb3fe13 100644 --- a/lib/rules/key-spacing.js +++ b/lib/rules/key-spacing.js @@ -326,7 +326,7 @@ module.exports = { singleLineOptions = ruleOptions.singleLine, alignmentOptions = ruleOptions.align || null; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines if the given property is key-value property. diff --git a/lib/rules/keyword-spacing.js b/lib/rules/keyword-spacing.js index 8c6a36f2633..8ed82199810 100644 --- a/lib/rules/keyword-spacing.js +++ b/lib/rules/keyword-spacing.js @@ -108,7 +108,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const tokensToIgnore = new WeakSet(); diff --git a/lib/rules/line-comment-position.js b/lib/rules/line-comment-position.js index 30656f33fc8..314fac16731 100644 --- a/lib/rules/line-comment-position.js +++ b/lib/rules/line-comment-position.js @@ -78,7 +78,7 @@ module.exports = { const defaultIgnoreRegExp = astUtils.COMMENTS_IGNORE_PATTERN; const fallThroughRegExp = /^\s*falls?\s?through/u; const customIgnoreRegExp = new RegExp(ignorePattern, "u"); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Public diff --git a/lib/rules/linebreak-style.js b/lib/rules/linebreak-style.js index d6af907798b..d8f36094b2e 100644 --- a/lib/rules/linebreak-style.js +++ b/lib/rules/linebreak-style.js @@ -40,7 +40,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/lines-around-comment.js b/lib/rules/lines-around-comment.js index 8092939562a..10aeba3cbc1 100644 --- a/lib/rules/lines-around-comment.js +++ b/lib/rules/lines-around-comment.js @@ -138,7 +138,7 @@ module.exports = { options.beforeBlockComment = typeof options.beforeBlockComment !== "undefined" ? options.beforeBlockComment : true; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const lines = sourceCode.lines, numLines = lines.length + 1, diff --git a/lib/rules/lines-around-directive.js b/lib/rules/lines-around-directive.js index 9360a4046e6..1c82d8f98d6 100644 --- a/lib/rules/lines-around-directive.js +++ b/lib/rules/lines-around-directive.js @@ -54,7 +54,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const config = context.options[0] || "always"; const expectLineBefore = typeof config === "string" ? config : config.before; const expectLineAfter = typeof config === "string" ? config : config.after; diff --git a/lib/rules/lines-between-class-members.js b/lib/rules/lines-between-class-members.js index 065feaf13cd..dee4bab5f54 100644 --- a/lib/rules/lines-between-class-members.js +++ b/lib/rules/lines-between-class-members.js @@ -55,7 +55,7 @@ module.exports = { options[0] = context.options[0] || "always"; options[1] = context.options[1] || { exceptAfterSingleLine: false }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Gets a pair of tokens that should be used to check lines between two class member nodes. diff --git a/lib/rules/logical-assignment-operators.js b/lib/rules/logical-assignment-operators.js index ba9ab198e30..d373bec6d09 100644 --- a/lib/rules/logical-assignment-operators.js +++ b/lib/rules/logical-assignment-operators.js @@ -205,7 +205,7 @@ module.exports = { create(context) { const mode = context.options[0] === "never" ? "never" : "always"; const checkIf = mode === "always" && context.options.length > 1 && context.options[1].enforceForIfStatements; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const isStrict = sourceCode.getScope(sourceCode.ast).isStrict; /** diff --git a/lib/rules/max-len.js b/lib/rules/max-len.js index f8d0aac464c..59e85214a29 100644 --- a/lib/rules/max-len.js +++ b/lib/rules/max-len.js @@ -97,7 +97,7 @@ module.exports = { */ const URL_REGEXP = /[^:/?#]:\/\/[^?#]/u; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Computes the length of a line that may contain tabs. The width of each diff --git a/lib/rules/max-lines-per-function.js b/lib/rules/max-lines-per-function.js index 5ad95984122..f981922a74a 100644 --- a/lib/rules/max-lines-per-function.js +++ b/lib/rules/max-lines-per-function.js @@ -85,7 +85,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const lines = sourceCode.lines; const option = context.options[0]; diff --git a/lib/rules/max-lines.js b/lib/rules/max-lines.js index 484a8afaa5c..e85d4429081 100644 --- a/lib/rules/max-lines.js +++ b/lib/rules/max-lines.js @@ -87,7 +87,7 @@ module.exports = { const skipComments = option && option.skipComments; const skipBlankLines = option && option.skipBlankLines; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Returns whether or not a token is a comment node type diff --git a/lib/rules/max-params.js b/lib/rules/max-params.js index 587be3e477c..213477a15c6 100644 --- a/lib/rules/max-params.js +++ b/lib/rules/max-params.js @@ -57,7 +57,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const option = context.options[0]; let numParams = 3; diff --git a/lib/rules/max-statements-per-line.js b/lib/rules/max-statements-per-line.js index 8c48acfb820..b9665048764 100644 --- a/lib/rules/max-statements-per-line.js +++ b/lib/rules/max-statements-per-line.js @@ -45,7 +45,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, options = context.options[0] || {}, maxStatementsPerLine = typeof options.max !== "undefined" ? options.max : 1; diff --git a/lib/rules/multiline-comment-style.js b/lib/rules/multiline-comment-style.js index 0c949be6417..6da9862015c 100644 --- a/lib/rules/multiline-comment-style.js +++ b/lib/rules/multiline-comment-style.js @@ -65,7 +65,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const option = context.options[0] || "starred-block"; const params = context.options[1] || {}; const checkJSDoc = !!params.checkJSDoc; diff --git a/lib/rules/multiline-ternary.js b/lib/rules/multiline-ternary.js index ec2174757ad..f156fe32bb1 100644 --- a/lib/rules/multiline-ternary.js +++ b/lib/rules/multiline-ternary.js @@ -39,7 +39,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const option = context.options[0]; const multiline = option !== "never"; const allowSingleLine = option === "always-multiline"; diff --git a/lib/rules/new-cap.js b/lib/rules/new-cap.js index b3d5b6414f9..f81e42fd0c8 100644 --- a/lib/rules/new-cap.js +++ b/lib/rules/new-cap.js @@ -147,7 +147,7 @@ module.exports = { const listeners = {}; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/new-parens.js b/lib/rules/new-parens.js index 3b1219f7f36..e8667310f29 100644 --- a/lib/rules/new-parens.js +++ b/lib/rules/new-parens.js @@ -46,7 +46,7 @@ module.exports = { const options = context.options; const always = options[0] !== "never"; // Default is always - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { NewExpression(node) { diff --git a/lib/rules/newline-after-var.js b/lib/rules/newline-after-var.js index 340a6136b0f..5c9b5fbd10f 100644 --- a/lib/rules/newline-after-var.js +++ b/lib/rules/newline-after-var.js @@ -43,7 +43,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // Default `mode` to "always". const mode = context.options[0] === "never" ? "never" : "always"; diff --git a/lib/rules/newline-before-return.js b/lib/rules/newline-before-return.js index 0c91ff1527f..73d8ef99ff3 100644 --- a/lib/rules/newline-before-return.js +++ b/lib/rules/newline-before-return.js @@ -31,7 +31,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/newline-per-chained-call.js b/lib/rules/newline-per-chained-call.js index 49d09a10b88..b2e6cd9e49d 100644 --- a/lib/rules/newline-per-chained-call.js +++ b/lib/rules/newline-per-chained-call.js @@ -47,7 +47,7 @@ module.exports = { const options = context.options[0] || {}, ignoreChainWithDepth = options.ignoreChainWithDepth || 2; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Get the prefix of a given MemberExpression node. diff --git a/lib/rules/no-alert.js b/lib/rules/no-alert.js index ee9a737ccbf..cc872856501 100644 --- a/lib/rules/no-alert.js +++ b/lib/rules/no-alert.js @@ -101,7 +101,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { diff --git a/lib/rules/no-async-promise-executor.js b/lib/rules/no-async-promise-executor.js index f31d3930bee..ea6c851147c 100644 --- a/lib/rules/no-async-promise-executor.js +++ b/lib/rules/no-async-promise-executor.js @@ -30,7 +30,7 @@ module.exports = { return { "NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) { context.report({ - node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"), + node: context.sourceCode.getFirstToken(node.arguments[0], token => token.value === "async"), messageId: "async" }); } diff --git a/lib/rules/no-catch-shadow.js b/lib/rules/no-catch-shadow.js index 48e0e7fe7ec..f9d8552437d 100644 --- a/lib/rules/no-catch-shadow.js +++ b/lib/rules/no-catch-shadow.js @@ -39,7 +39,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-class-assign.js b/lib/rules/no-class-assign.js index 92ae9f99c90..49f3b844e7e 100644 --- a/lib/rules/no-class-assign.js +++ b/lib/rules/no-class-assign.js @@ -31,7 +31,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Finds and reports references that are non initializer and writable. diff --git a/lib/rules/no-cond-assign.js b/lib/rules/no-cond-assign.js index 10d4492455c..952920215aa 100644 --- a/lib/rules/no-cond-assign.js +++ b/lib/rules/no-cond-assign.js @@ -57,7 +57,7 @@ module.exports = { const prohibitAssign = (context.options[0] || "except-parens"); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Check whether an AST node is the test expression for a conditional statement. diff --git a/lib/rules/no-confusing-arrow.js b/lib/rules/no-confusing-arrow.js index 12d8ff96247..de6e2f30c2e 100644 --- a/lib/rules/no-confusing-arrow.js +++ b/lib/rules/no-confusing-arrow.js @@ -56,7 +56,7 @@ module.exports = { const config = context.options[0] || {}; const allowParens = config.allowParens || (config.allowParens === void 0); const onlyOneSimpleParam = config.onlyOneSimpleParam; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** diff --git a/lib/rules/no-console.js b/lib/rules/no-console.js index 33d231a9f0e..f257098d38b 100644 --- a/lib/rules/no-console.js +++ b/lib/rules/no-console.js @@ -51,7 +51,7 @@ module.exports = { create(context) { const options = context.options[0] || {}; const allowed = options.allow || []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks whether the given reference is 'console' or not. diff --git a/lib/rules/no-const-assign.js b/lib/rules/no-const-assign.js index 993675ea1cb..0ceaf7ea5ed 100644 --- a/lib/rules/no-const-assign.js +++ b/lib/rules/no-const-assign.js @@ -31,7 +31,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Finds and reports references that are non initializer and writable. diff --git a/lib/rules/no-constant-binary-expression.js b/lib/rules/no-constant-binary-expression.js index 26ff6ad55ea..845255a0cc2 100644 --- a/lib/rules/no-constant-binary-expression.js +++ b/lib/rules/no-constant-binary-expression.js @@ -453,7 +453,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { LogicalExpression(node) { diff --git a/lib/rules/no-constant-condition.js b/lib/rules/no-constant-condition.js index 33394e1ea69..24abe363280 100644 --- a/lib/rules/no-constant-condition.js +++ b/lib/rules/no-constant-condition.js @@ -48,7 +48,7 @@ module.exports = { const options = context.options[0] || {}, checkLoops = options.checkLoops !== false, loopSetStack = []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let loopsInCurrentScope = new Set(); diff --git a/lib/rules/no-div-regex.js b/lib/rules/no-div-regex.js index c0f3ce89a28..208f840bef6 100644 --- a/lib/rules/no-div-regex.js +++ b/lib/rules/no-div-regex.js @@ -30,7 +30,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { diff --git a/lib/rules/no-dupe-args.js b/lib/rules/no-dupe-args.js index f52a4062bf8..c04ede5af58 100644 --- a/lib/rules/no-dupe-args.js +++ b/lib/rules/no-dupe-args.js @@ -29,7 +29,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-dupe-else-if.js b/lib/rules/no-dupe-else-if.js index d887a982895..60f436d1d79 100644 --- a/lib/rules/no-dupe-else-if.js +++ b/lib/rules/no-dupe-else-if.js @@ -65,7 +65,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether the two given nodes are considered to be equal. In particular, given that the nodes diff --git a/lib/rules/no-duplicate-case.js b/lib/rules/no-duplicate-case.js index d15eb030602..839f357e74f 100644 --- a/lib/rules/no-duplicate-case.js +++ b/lib/rules/no-duplicate-case.js @@ -35,7 +35,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether the two given nodes are considered to be equal. diff --git a/lib/rules/no-else-return.js b/lib/rules/no-else-return.js index 36a92e3dde8..9dbf569651c 100644 --- a/lib/rules/no-else-return.js +++ b/lib/rules/no-else-return.js @@ -47,7 +47,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-empty-function.js b/lib/rules/no-empty-function.js index c16aee87c2c..2fcb75534ac 100644 --- a/lib/rules/no-empty-function.js +++ b/lib/rules/no-empty-function.js @@ -123,7 +123,7 @@ module.exports = { const options = context.options[0] || {}; const allowed = options.allow || []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports a given function node if the node matches the following patterns. diff --git a/lib/rules/no-empty-static-block.js b/lib/rules/no-empty-static-block.js index e810097bb38..81fc449b8cf 100644 --- a/lib/rules/no-empty-static-block.js +++ b/lib/rules/no-empty-static-block.js @@ -27,7 +27,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { StaticBlock(node) { diff --git a/lib/rules/no-empty.js b/lib/rules/no-empty.js index 633ddd001b9..1c157963e9d 100644 --- a/lib/rules/no-empty.js +++ b/lib/rules/no-empty.js @@ -49,7 +49,7 @@ module.exports = { const options = context.options[0] || {}, allowEmptyCatch = options.allowEmptyCatch || false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { BlockStatement(node) { diff --git a/lib/rules/no-eval.js b/lib/rules/no-eval.js index 42f8182c48a..a059526a68b 100644 --- a/lib/rules/no-eval.js +++ b/lib/rules/no-eval.js @@ -68,7 +68,7 @@ module.exports = { context.options[0] && context.options[0].allowIndirect ); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let funcInfo = null; /** diff --git a/lib/rules/no-ex-assign.js b/lib/rules/no-ex-assign.js index aec60cb9597..d0e9febae04 100644 --- a/lib/rules/no-ex-assign.js +++ b/lib/rules/no-ex-assign.js @@ -31,7 +31,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Finds and reports references that are non initializer and writable. diff --git a/lib/rules/no-extend-native.js b/lib/rules/no-extend-native.js index c4c408bdc8b..fcbb3855725 100644 --- a/lib/rules/no-extend-native.js +++ b/lib/rules/no-extend-native.js @@ -51,7 +51,7 @@ module.exports = { create(context) { const config = context.options[0] || {}; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const exceptions = new Set(config.exceptions || []); const modifiedBuiltins = new Set( Object.keys(globals.builtin) diff --git a/lib/rules/no-extra-bind.js b/lib/rules/no-extra-bind.js index ec4ca350042..e1e72b0c745 100644 --- a/lib/rules/no-extra-bind.js +++ b/lib/rules/no-extra-bind.js @@ -40,7 +40,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let scopeInfo = null; /** diff --git a/lib/rules/no-extra-boolean-cast.js b/lib/rules/no-extra-boolean-cast.js index 108ea5824d0..f342533bfc9 100644 --- a/lib/rules/no-extra-boolean-cast.js +++ b/lib/rules/no-extra-boolean-cast.js @@ -48,7 +48,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // Node types which have a test which will coerce values to booleans. const BOOLEAN_NODE_TYPES = new Set([ diff --git a/lib/rules/no-extra-label.js b/lib/rules/no-extra-label.js index 0f34a624aac..45ff441d001 100644 --- a/lib/rules/no-extra-label.js +++ b/lib/rules/no-extra-label.js @@ -35,7 +35,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let scopeInfo = null; /** diff --git a/lib/rules/no-extra-parens.js b/lib/rules/no-extra-parens.js index 0f9787deb3a..0f59d7dd382 100644 --- a/lib/rules/no-extra-parens.js +++ b/lib/rules/no-extra-parens.js @@ -70,7 +70,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const tokensToIgnore = new WeakSet(); const precedence = astUtils.getPrecedence; diff --git a/lib/rules/no-extra-semi.js b/lib/rules/no-extra-semi.js index dec104199a4..ebf145f9cd1 100644 --- a/lib/rules/no-extra-semi.js +++ b/lib/rules/no-extra-semi.js @@ -36,7 +36,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports an unnecessary semicolon error. @@ -54,7 +54,7 @@ module.exports = { * tokens to avoid conflicting with semi. * https://github.com/eslint/eslint/issues/7928 */ - return new FixTracker(fixer, context.getSourceCode()) + return new FixTracker(fixer, context.sourceCode) .retainSurroundingTokens(nodeOrToken) .remove(nodeOrToken); } diff --git a/lib/rules/no-fallthrough.js b/lib/rules/no-fallthrough.js index 60616de0edf..bd2ee9bbe2c 100644 --- a/lib/rules/no-fallthrough.js +++ b/lib/rules/no-fallthrough.js @@ -35,7 +35,7 @@ function isFallThroughComment(comment, fallthroughCommentPattern) { * @returns {boolean} `true` if the case has a valid fallthrough comment. */ function hasFallthroughComment(caseWhichFallsThrough, subsequentCase, context, fallthroughCommentPattern) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (caseWhichFallsThrough.consequent.length === 1 && caseWhichFallsThrough.consequent[0].type === "BlockStatement") { const trailingCloseBrace = sourceCode.getLastToken(caseWhichFallsThrough.consequent[0]); @@ -110,7 +110,7 @@ module.exports = { create(context) { const options = context.options[0] || {}; let currentCodePath = null; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const allowEmptyCase = options.allowEmptyCase || false; /* diff --git a/lib/rules/no-floating-decimal.js b/lib/rules/no-floating-decimal.js index ed0fc3096f1..c26876440a5 100644 --- a/lib/rules/no-floating-decimal.js +++ b/lib/rules/no-floating-decimal.js @@ -35,7 +35,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { Literal(node) { diff --git a/lib/rules/no-func-assign.js b/lib/rules/no-func-assign.js index 4cbcbab4a6f..8084af6eb4d 100644 --- a/lib/rules/no-func-assign.js +++ b/lib/rules/no-func-assign.js @@ -31,7 +31,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports a reference if is non initializer and writable. diff --git a/lib/rules/no-global-assign.js b/lib/rules/no-global-assign.js index e5b0f4b028a..99ae7a2ee5e 100644 --- a/lib/rules/no-global-assign.js +++ b/lib/rules/no-global-assign.js @@ -41,7 +41,7 @@ module.exports = { create(context) { const config = context.options[0]; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const exceptions = (config && config.exceptions) || []; /** diff --git a/lib/rules/no-implicit-coercion.js b/lib/rules/no-implicit-coercion.js index 46f45eec59d..36baad3835e 100644 --- a/lib/rules/no-implicit-coercion.js +++ b/lib/rules/no-implicit-coercion.js @@ -235,7 +235,7 @@ module.exports = { create(context) { const options = parseOptions(context.options[0] || {}); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports an error and autofixes the node diff --git a/lib/rules/no-implicit-globals.js b/lib/rules/no-implicit-globals.js index bc69029a34b..2a182477c0e 100644 --- a/lib/rules/no-implicit-globals.js +++ b/lib/rules/no-implicit-globals.js @@ -43,7 +43,7 @@ module.exports = { create(context) { const checkLexicalBindings = context.options[0] && context.options[0].lexicalBindings === true; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports the node. diff --git a/lib/rules/no-implied-eval.js b/lib/rules/no-implied-eval.js index 9ce7b4f565a..9a84f8cbaf1 100644 --- a/lib/rules/no-implied-eval.js +++ b/lib/rules/no-implied-eval.js @@ -37,7 +37,7 @@ module.exports = { create(context) { const GLOBAL_CANDIDATES = Object.freeze(["global", "window", "globalThis"]); const EVAL_LIKE_FUNC_PATTERN = /^(?:set(?:Interval|Timeout)|execScript)$/u; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks whether a node is evaluated as a string or not. diff --git a/lib/rules/no-import-assign.js b/lib/rules/no-import-assign.js index 9f4d5809676..c69988666ab 100644 --- a/lib/rules/no-import-assign.js +++ b/lib/rules/no-import-assign.js @@ -194,7 +194,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { ImportDeclaration(node) { diff --git a/lib/rules/no-inline-comments.js b/lib/rules/no-inline-comments.js index 9be6615ffc3..d96e6472d13 100644 --- a/lib/rules/no-inline-comments.js +++ b/lib/rules/no-inline-comments.js @@ -39,7 +39,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = context.options[0]; let customIgnoreRegExp; diff --git a/lib/rules/no-invalid-this.js b/lib/rules/no-invalid-this.js index 51335511aa5..49ecbe514c6 100644 --- a/lib/rules/no-invalid-this.js +++ b/lib/rules/no-invalid-this.js @@ -63,7 +63,7 @@ module.exports = { const options = context.options[0] || {}; const capIsConstructor = options.capIsConstructor !== false; const stack = [], - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; /** * Gets the current checking context. diff --git a/lib/rules/no-irregular-whitespace.js b/lib/rules/no-irregular-whitespace.js index dea9947f442..67519b5e851 100644 --- a/lib/rules/no-irregular-whitespace.js +++ b/lib/rules/no-irregular-whitespace.js @@ -78,7 +78,7 @@ module.exports = { const skipRegExps = !!options.skipRegExps; const skipTemplates = !!options.skipTemplates; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const commentNodes = sourceCode.getAllComments(); /** diff --git a/lib/rules/no-label-var.js b/lib/rules/no-label-var.js index 329d7f136b4..bf33cd157ba 100644 --- a/lib/rules/no-label-var.js +++ b/lib/rules/no-label-var.js @@ -34,7 +34,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-lone-blocks.js b/lib/rules/no-lone-blocks.js index bfd546cdd87..767eec2becf 100644 --- a/lib/rules/no-lone-blocks.js +++ b/lib/rules/no-lone-blocks.js @@ -33,7 +33,7 @@ module.exports = { // A stack of lone blocks to be checked for block-level bindings const loneBlocks = []; let ruleDef; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports a node as invalid. diff --git a/lib/rules/no-lonely-if.js b/lib/rules/no-lonely-if.js index 562b110d7b5..eefd2c688e9 100644 --- a/lib/rules/no-lonely-if.js +++ b/lib/rules/no-lonely-if.js @@ -28,7 +28,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { IfStatement(node) { diff --git a/lib/rules/no-loop-func.js b/lib/rules/no-loop-func.js index 0f222eb35ba..e1d65fdc92c 100644 --- a/lib/rules/no-loop-func.js +++ b/lib/rules/no-loop-func.js @@ -168,7 +168,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports functions which match the following condition: diff --git a/lib/rules/no-misleading-character-class.js b/lib/rules/no-misleading-character-class.js index e216c38159d..47ee84ec857 100644 --- a/lib/rules/no-misleading-character-class.js +++ b/lib/rules/no-misleading-character-class.js @@ -125,7 +125,7 @@ module.exports = { } }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const parser = new RegExpParser(); /** diff --git a/lib/rules/no-mixed-operators.js b/lib/rules/no-mixed-operators.js index 93b874f24ef..724abe09466 100644 --- a/lib/rules/no-mixed-operators.js +++ b/lib/rules/no-mixed-operators.js @@ -122,7 +122,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = normalizeOptions(context.options[0]); /** diff --git a/lib/rules/no-mixed-spaces-and-tabs.js b/lib/rules/no-mixed-spaces-and-tabs.js index 51a6ef65476..a18e4f30d0a 100644 --- a/lib/rules/no-mixed-spaces-and-tabs.js +++ b/lib/rules/no-mixed-spaces-and-tabs.js @@ -31,7 +31,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let smartTabs; diff --git a/lib/rules/no-multi-spaces.js b/lib/rules/no-multi-spaces.js index eb0603b1fed..62074e657ae 100644 --- a/lib/rules/no-multi-spaces.js +++ b/lib/rules/no-multi-spaces.js @@ -52,7 +52,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = context.options[0] || {}; const ignoreEOLComments = options.ignoreEOLComments; const exceptions = Object.assign({ Property: true }, options.exceptions); diff --git a/lib/rules/no-multiple-empty-lines.js b/lib/rules/no-multiple-empty-lines.js index e6bbf190d73..2c0fbf2c6ab 100644 --- a/lib/rules/no-multiple-empty-lines.js +++ b/lib/rules/no-multiple-empty-lines.js @@ -64,7 +64,7 @@ module.exports = { maxBOF = typeof context.options[0].maxBOF !== "undefined" ? context.options[0].maxBOF : max; } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // Swallow the final newline, as some editors add it automatically and we don't want it to cause an issue const allLines = sourceCode.lines[sourceCode.lines.length - 1] === "" ? sourceCode.lines.slice(0, -1) : sourceCode.lines; diff --git a/lib/rules/no-native-reassign.js b/lib/rules/no-native-reassign.js index 6399b6ea698..e3fed445102 100644 --- a/lib/rules/no-native-reassign.js +++ b/lib/rules/no-native-reassign.js @@ -47,7 +47,7 @@ module.exports = { create(context) { const config = context.options[0]; const exceptions = (config && config.exceptions) || []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports write references. diff --git a/lib/rules/no-new-func.js b/lib/rules/no-new-func.js index 86a5f7080db..d58b2d71547 100644 --- a/lib/rules/no-new-func.js +++ b/lib/rules/no-new-func.js @@ -40,7 +40,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Program:exit"(node) { diff --git a/lib/rules/no-new-native-nonconstructor.js b/lib/rules/no-new-native-nonconstructor.js index 97fa588220c..ee70d281d75 100644 --- a/lib/rules/no-new-native-nonconstructor.js +++ b/lib/rules/no-new-native-nonconstructor.js @@ -35,7 +35,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Program:exit"(node) { diff --git a/lib/rules/no-new-object.js b/lib/rules/no-new-object.js index 60073b32d34..08a482be715 100644 --- a/lib/rules/no-new-object.js +++ b/lib/rules/no-new-object.js @@ -35,7 +35,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { NewExpression(node) { diff --git a/lib/rules/no-new-symbol.js b/lib/rules/no-new-symbol.js index 2bcec247354..99830220244 100644 --- a/lib/rules/no-new-symbol.js +++ b/lib/rules/no-new-symbol.js @@ -29,7 +29,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Program:exit"(node) { diff --git a/lib/rules/no-nonoctal-decimal-escape.js b/lib/rules/no-nonoctal-decimal-escape.js index 57252f4a5a2..5939390fd9a 100644 --- a/lib/rules/no-nonoctal-decimal-escape.js +++ b/lib/rules/no-nonoctal-decimal-escape.js @@ -49,7 +49,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Creates a new Suggestion object. diff --git a/lib/rules/no-obj-calls.js b/lib/rules/no-obj-calls.js index abf0feb55e3..ee767ea2fa3 100644 --- a/lib/rules/no-obj-calls.js +++ b/lib/rules/no-obj-calls.js @@ -58,7 +58,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { Program(node) { diff --git a/lib/rules/no-param-reassign.js b/lib/rules/no-param-reassign.js index ac389b5bbbb..607cafd3837 100644 --- a/lib/rules/no-param-reassign.js +++ b/lib/rules/no-param-reassign.js @@ -70,7 +70,7 @@ module.exports = { const props = context.options[0] && context.options[0].props; const ignoredPropertyAssignmentsFor = context.options[0] && context.options[0].ignorePropertyModificationsFor || []; const ignoredPropertyAssignmentsForRegex = context.options[0] && context.options[0].ignorePropertyModificationsForRegex || []; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks whether or not the reference modifies properties of its variable. diff --git a/lib/rules/no-promise-executor-return.js b/lib/rules/no-promise-executor-return.js index 964446abd72..d46a730e474 100644 --- a/lib/rules/no-promise-executor-return.js +++ b/lib/rules/no-promise-executor-return.js @@ -84,7 +84,7 @@ module.exports = { create(context) { let funcInfo = null; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports the given node. diff --git a/lib/rules/no-redeclare.js b/lib/rules/no-redeclare.js index a33565bf73e..8a4877e8a3c 100644 --- a/lib/rules/no-redeclare.js +++ b/lib/rules/no-redeclare.js @@ -50,7 +50,7 @@ module.exports = { context.options[0].builtinGlobals ) }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Iterate declarations of a given variable. diff --git a/lib/rules/no-regex-spaces.js b/lib/rules/no-regex-spaces.js index 6252badf5d7..e7fae6d4055 100644 --- a/lib/rules/no-regex-spaces.js +++ b/lib/rules/no-regex-spaces.js @@ -54,7 +54,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Validate regular expression diff --git a/lib/rules/no-restricted-exports.js b/lib/rules/no-restricted-exports.js index e237005fb87..a1d54b085fd 100644 --- a/lib/rules/no-restricted-exports.js +++ b/lib/rules/no-restricted-exports.js @@ -99,7 +99,7 @@ module.exports = { const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports); const restrictDefaultExports = context.options[0] && context.options[0].restrictDefaultExports; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks and reports given exported name. diff --git a/lib/rules/no-restricted-globals.js b/lib/rules/no-restricted-globals.js index a211a7e2673..919a8ee0ad8 100644 --- a/lib/rules/no-restricted-globals.js +++ b/lib/rules/no-restricted-globals.js @@ -50,7 +50,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // If no globals are restricted, we don't need to do anything if (context.options.length === 0) { diff --git a/lib/rules/no-restricted-imports.js b/lib/rules/no-restricted-imports.js index 1d910773e5b..6abfcacae13 100644 --- a/lib/rules/no-restricted-imports.js +++ b/lib/rules/no-restricted-imports.js @@ -147,7 +147,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = Array.isArray(context.options) ? context.options : []; const isPathAndPatternsObject = typeof options[0] === "object" && diff --git a/lib/rules/no-return-assign.js b/lib/rules/no-return-assign.js index 6d5bddf361b..73caf0e6bd3 100644 --- a/lib/rules/no-return-assign.js +++ b/lib/rules/no-return-assign.js @@ -45,7 +45,7 @@ module.exports = { create(context) { const always = (context.options[0] || "except-parens") !== "except-parens"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { AssignmentExpression(node) { diff --git a/lib/rules/no-return-await.js b/lib/rules/no-return-await.js index b7ec40bb607..b5abf14c69b 100644 --- a/lib/rules/no-return-await.js +++ b/lib/rules/no-return-await.js @@ -44,14 +44,14 @@ module.exports = { */ function reportUnnecessaryAwait(node) { context.report({ - node: context.getSourceCode().getFirstToken(node), + node: context.sourceCode.getFirstToken(node), loc: node.loc, messageId: "redundantUseOfAwait", suggest: [ { messageId: "removeAwait", fix(fixer) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const [awaitToken, tokenAfterAwait] = sourceCode.getFirstTokens(node, 2); const areAwaitAndAwaitedExpressionOnTheSameLine = awaitToken.loc.start.line === tokenAfterAwait.loc.start.line; diff --git a/lib/rules/no-self-assign.js b/lib/rules/no-self-assign.js index d12e732a815..33ac8fb5085 100644 --- a/lib/rules/no-self-assign.js +++ b/lib/rules/no-self-assign.js @@ -154,7 +154,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const [{ props = true } = {}] = context.options; /** diff --git a/lib/rules/no-self-compare.js b/lib/rules/no-self-compare.js index e966ca1922c..3b076eba83c 100644 --- a/lib/rules/no-self-compare.js +++ b/lib/rules/no-self-compare.js @@ -29,7 +29,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether two nodes are composed of the same tokens. diff --git a/lib/rules/no-sequences.js b/lib/rules/no-sequences.js index 3f226bab859..cd21fc7842c 100644 --- a/lib/rules/no-sequences.js +++ b/lib/rules/no-sequences.js @@ -51,7 +51,7 @@ module.exports = { create(context) { const options = Object.assign({}, DEFAULT_OPTIONS, context.options[0]); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Parts of the grammar that are required to have parens. diff --git a/lib/rules/no-setter-return.js b/lib/rules/no-setter-return.js index 77b9dd4591b..a5abaaa7e53 100644 --- a/lib/rules/no-setter-return.js +++ b/lib/rules/no-setter-return.js @@ -156,7 +156,7 @@ module.exports = { create(context) { let funcInfo = null; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Creates and pushes to the stack a function info object for the given function node. diff --git a/lib/rules/no-shadow-restricted-names.js b/lib/rules/no-shadow-restricted-names.js index 2024c309557..29560fffc7f 100644 --- a/lib/rules/no-shadow-restricted-names.js +++ b/lib/rules/no-shadow-restricted-names.js @@ -43,7 +43,7 @@ module.exports = { const RESTRICTED = new Set(["undefined", "NaN", "Infinity", "arguments", "eval"]); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "VariableDeclaration, :function, CatchClause"(node) { diff --git a/lib/rules/no-shadow.js b/lib/rules/no-shadow.js index b50db5bb5bf..3e4d99822a8 100644 --- a/lib/rules/no-shadow.js +++ b/lib/rules/no-shadow.js @@ -67,7 +67,7 @@ module.exports = { allow: (context.options[0] && context.options[0].allow) || [], ignoreOnInitialization: context.options[0] && context.options[0].ignoreOnInitialization }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks whether or not a given location is inside of the range of a given node. diff --git a/lib/rules/no-spaced-func.js b/lib/rules/no-spaced-func.js index 91836df51fe..d79c18440b0 100644 --- a/lib/rules/no-spaced-func.js +++ b/lib/rules/no-spaced-func.js @@ -35,7 +35,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Check if open space is present in a function name diff --git a/lib/rules/no-tabs.js b/lib/rules/no-tabs.js index 3672aa2d592..b33690c2441 100644 --- a/lib/rules/no-tabs.js +++ b/lib/rules/no-tabs.js @@ -43,7 +43,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const allowIndentationTabs = context.options && context.options[0] && context.options[0].allowIndentationTabs; return { diff --git a/lib/rules/no-trailing-spaces.js b/lib/rules/no-trailing-spaces.js index 05aeace7a1c..1674de54207 100644 --- a/lib/rules/no-trailing-spaces.js +++ b/lib/rules/no-trailing-spaces.js @@ -50,7 +50,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const BLANK_CLASS = "[ \t\u00a0\u2000-\u200b\u3000]", SKIP_BLANK = `^${BLANK_CLASS}*$`, diff --git a/lib/rules/no-undef-init.js b/lib/rules/no-undef-init.js index 1efe8292025..be19d6f9526 100644 --- a/lib/rules/no-undef-init.js +++ b/lib/rules/no-undef-init.js @@ -32,7 +32,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { diff --git a/lib/rules/no-undef.js b/lib/rules/no-undef.js index 397770a71da..fe470286c04 100644 --- a/lib/rules/no-undef.js +++ b/lib/rules/no-undef.js @@ -54,7 +54,7 @@ module.exports = { create(context) { const options = context.options[0]; const considerTypeOf = options && options.typeof === true || false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Program:exit"(node) { diff --git a/lib/rules/no-undefined.js b/lib/rules/no-undefined.js index a939eb13370..8f47ca1b020 100644 --- a/lib/rules/no-undefined.js +++ b/lib/rules/no-undefined.js @@ -28,7 +28,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Report an invalid "undefined" identifier node. diff --git a/lib/rules/no-underscore-dangle.js b/lib/rules/no-underscore-dangle.js index a7ca6a4569d..a0e05c6c1cc 100644 --- a/lib/rules/no-underscore-dangle.js +++ b/lib/rules/no-underscore-dangle.js @@ -84,7 +84,7 @@ module.exports = { const allowFunctionParams = typeof options.allowFunctionParams !== "undefined" ? options.allowFunctionParams : true; const allowInArrayDestructuring = typeof options.allowInArrayDestructuring !== "undefined" ? options.allowInArrayDestructuring : true; const allowInObjectDestructuring = typeof options.allowInObjectDestructuring !== "undefined" ? options.allowInObjectDestructuring : true; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/no-unexpected-multiline.js b/lib/rules/no-unexpected-multiline.js index 0ed1ec99afc..810c08b011b 100644 --- a/lib/rules/no-unexpected-multiline.js +++ b/lib/rules/no-unexpected-multiline.js @@ -38,7 +38,7 @@ module.exports = { const REGEX_FLAG_MATCHER = /^[gimsuy]+$/u; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Check to see if there is a newline between the node and the following open bracket diff --git a/lib/rules/no-unmodified-loop-condition.js b/lib/rules/no-unmodified-loop-condition.js index 666f470f507..768a15573ac 100644 --- a/lib/rules/no-unmodified-loop-condition.js +++ b/lib/rules/no-unmodified-loop-condition.js @@ -175,7 +175,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let groupMap = null; /** diff --git a/lib/rules/no-unneeded-ternary.js b/lib/rules/no-unneeded-ternary.js index 8f2bb1a39dd..ab1bdc59cbf 100644 --- a/lib/rules/no-unneeded-ternary.js +++ b/lib/rules/no-unneeded-ternary.js @@ -58,7 +58,7 @@ module.exports = { create(context) { const options = context.options[0] || {}; const defaultAssignment = options.defaultAssignment !== false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Test if the node is a boolean literal diff --git a/lib/rules/no-unreachable.js b/lib/rules/no-unreachable.js index 356b25e1b9e..6216a73a235 100644 --- a/lib/rules/no-unreachable.js +++ b/lib/rules/no-unreachable.js @@ -130,7 +130,7 @@ module.exports = { let constructorInfo = null; /** @type {ConsecutiveRange} */ - const range = new ConsecutiveRange(context.getSourceCode()); + const range = new ConsecutiveRange(context.sourceCode); /** * Reports a given node if it's unreachable. diff --git a/lib/rules/no-unsafe-negation.js b/lib/rules/no-unsafe-negation.js index 87fbde179c2..cabd7e2ccc2 100644 --- a/lib/rules/no-unsafe-negation.js +++ b/lib/rules/no-unsafe-negation.js @@ -82,7 +82,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = context.options[0] || {}; const enforceForOrderingRelations = options.enforceForOrderingRelations === true; diff --git a/lib/rules/no-unused-labels.js b/lib/rules/no-unused-labels.js index 7840a765765..9aa1067c681 100644 --- a/lib/rules/no-unused-labels.js +++ b/lib/rules/no-unused-labels.js @@ -30,7 +30,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let scopeInfo = null; /** diff --git a/lib/rules/no-unused-vars.js b/lib/rules/no-unused-vars.js index f99657ee5cf..be8af43dd41 100644 --- a/lib/rules/no-unused-vars.js +++ b/lib/rules/no-unused-vars.js @@ -84,7 +84,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const REST_PROPERTY_TYPE = /^(?:RestElement|(?:Experimental)?RestProperty)$/u; diff --git a/lib/rules/no-use-before-define.js b/lib/rules/no-use-before-define.js index c5482d23f85..9d6b043404a 100644 --- a/lib/rules/no-use-before-define.js +++ b/lib/rules/no-use-before-define.js @@ -258,7 +258,7 @@ module.exports = { create(context) { const options = parseOptions(context.options[0]); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether a given reference should be checked. diff --git a/lib/rules/no-useless-backreference.js b/lib/rules/no-useless-backreference.js index 5d19b78b389..c99ac411495 100644 --- a/lib/rules/no-useless-backreference.js +++ b/lib/rules/no-useless-backreference.js @@ -82,7 +82,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks and reports useless backreferences in the given regular expression. diff --git a/lib/rules/no-useless-call.js b/lib/rules/no-useless-call.js index 0fa4af53190..dea2b47a4a4 100644 --- a/lib/rules/no-useless-call.js +++ b/lib/rules/no-useless-call.js @@ -68,7 +68,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { diff --git a/lib/rules/no-useless-computed-key.js b/lib/rules/no-useless-computed-key.js index 82a0e34a5f8..f2d9f3341f5 100644 --- a/lib/rules/no-useless-computed-key.js +++ b/lib/rules/no-useless-computed-key.js @@ -113,7 +113,7 @@ module.exports = { } }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const enforceForClassMembers = context.options[0] && context.options[0].enforceForClassMembers; /** diff --git a/lib/rules/no-useless-concat.js b/lib/rules/no-useless-concat.js index f18124d8205..c566c62be8d 100644 --- a/lib/rules/no-useless-concat.js +++ b/lib/rules/no-useless-concat.js @@ -83,7 +83,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { BinaryExpression(node) { diff --git a/lib/rules/no-useless-escape.js b/lib/rules/no-useless-escape.js index e836ec4f0d2..8304d915f9e 100644 --- a/lib/rules/no-useless-escape.js +++ b/lib/rules/no-useless-escape.js @@ -101,7 +101,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports a node diff --git a/lib/rules/no-useless-rename.js b/lib/rules/no-useless-rename.js index a20bb610157..0c818fb2c2f 100644 --- a/lib/rules/no-useless-rename.js +++ b/lib/rules/no-useless-rename.js @@ -46,7 +46,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, options = context.options[0] || {}, ignoreDestructuring = options.ignoreDestructuring === true, ignoreImport = options.ignoreImport === true, diff --git a/lib/rules/no-useless-return.js b/lib/rules/no-useless-return.js index 26b99f2ae58..db1ccae9739 100644 --- a/lib/rules/no-useless-return.js +++ b/lib/rules/no-useless-return.js @@ -83,7 +83,7 @@ module.exports = { create(context) { const segmentInfoMap = new WeakMap(); const usedUnreachableSegments = new WeakSet(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let scopeInfo = null; /** diff --git a/lib/rules/no-var.js b/lib/rules/no-var.js index 70ed6b0367e..d45a91a1de8 100644 --- a/lib/rules/no-var.js +++ b/lib/rules/no-var.js @@ -199,7 +199,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks whether the variables which are defined by the given declarator node have their references in TDZ. diff --git a/lib/rules/no-warning-comments.js b/lib/rules/no-warning-comments.js index aabd47d80ef..c415bee7a7b 100644 --- a/lib/rules/no-warning-comments.js +++ b/lib/rules/no-warning-comments.js @@ -58,7 +58,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, configuration = context.options[0] || {}, warningTerms = configuration.terms || ["todo", "fixme", "xxx"], location = configuration.location || "start", diff --git a/lib/rules/no-whitespace-before-property.js b/lib/rules/no-whitespace-before-property.js index 8b0c4aad44e..1153314afe6 100644 --- a/lib/rules/no-whitespace-before-property.js +++ b/lib/rules/no-whitespace-before-property.js @@ -34,7 +34,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/nonblock-statement-body-position.js b/lib/rules/nonblock-statement-body-position.js index fd645f447ab..1ea2770ceb2 100644 --- a/lib/rules/nonblock-statement-body-position.js +++ b/lib/rules/nonblock-statement-body-position.js @@ -49,7 +49,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/object-curly-newline.js b/lib/rules/object-curly-newline.js index 7724ffafe5d..caf1982312a 100644 --- a/lib/rules/object-curly-newline.js +++ b/lib/rules/object-curly-newline.js @@ -185,7 +185,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const normalizedOptions = normalizeOptions(context.options[0]); /** diff --git a/lib/rules/object-curly-spacing.js b/lib/rules/object-curly-spacing.js index c87130a67ca..41ca428fe24 100644 --- a/lib/rules/object-curly-spacing.js +++ b/lib/rules/object-curly-spacing.js @@ -51,7 +51,7 @@ module.exports = { create(context) { const spaced = context.options[0] === "always", - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; /** * Determines whether an option is set, relative to the spacing option. @@ -81,7 +81,7 @@ module.exports = { * @returns {void} */ function reportNoBeginningSpace(node, token) { - const nextToken = context.getSourceCode().getTokenAfter(token, { includeComments: true }); + const nextToken = context.sourceCode.getTokenAfter(token, { includeComments: true }); context.report({ node, @@ -103,7 +103,7 @@ module.exports = { * @returns {void} */ function reportNoEndingSpace(node, token) { - const previousToken = context.getSourceCode().getTokenBefore(token, { includeComments: true }); + const previousToken = context.sourceCode.getTokenBefore(token, { includeComments: true }); context.report({ node, diff --git a/lib/rules/object-property-newline.js b/lib/rules/object-property-newline.js index 0ee14e7902c..deca9b555b1 100644 --- a/lib/rules/object-property-newline.js +++ b/lib/rules/object-property-newline.js @@ -53,7 +53,7 @@ module.exports = { ? "propertiesOnNewlineAll" : "propertiesOnNewline"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { ObjectExpression(node) { diff --git a/lib/rules/object-shorthand.js b/lib/rules/object-shorthand.js index e1b876b14b6..e4cb3a44573 100644 --- a/lib/rules/object-shorthand.js +++ b/lib/rules/object-shorthand.js @@ -123,7 +123,7 @@ module.exports = { : null; const AVOID_QUOTES = PARAMS.avoidQuotes; const AVOID_EXPLICIT_RETURN_ARROWS = !!PARAMS.avoidExplicitReturnArrows; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/one-var.js b/lib/rules/one-var.js index 5bce7e5ca61..abb1525b1a5 100644 --- a/lib/rules/one-var.js +++ b/lib/rules/one-var.js @@ -121,7 +121,7 @@ module.exports = { } } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/operator-assignment.js b/lib/rules/operator-assignment.js index ceb2d8d7eed..f71d73be75d 100644 --- a/lib/rules/operator-assignment.js +++ b/lib/rules/operator-assignment.js @@ -83,7 +83,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Returns the operator token of an AssignmentExpression or BinaryExpression diff --git a/lib/rules/operator-linebreak.js b/lib/rules/operator-linebreak.js index e2f151b7635..2b609f63576 100644 --- a/lib/rules/operator-linebreak.js +++ b/lib/rules/operator-linebreak.js @@ -69,7 +69,7 @@ module.exports = { styleOverrides[":"] = "before"; } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/padded-blocks.js b/lib/rules/padded-blocks.js index d616cd261b8..c6d1372ac75 100644 --- a/lib/rules/padded-blocks.js +++ b/lib/rules/padded-blocks.js @@ -96,7 +96,7 @@ module.exports = { options.allowSingleLineBlocks = exceptOptions.allowSingleLineBlocks === true; } - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Gets the open brace token from a given node. diff --git a/lib/rules/padding-line-between-statements.js b/lib/rules/padding-line-between-statements.js index 81795e50a26..be7e2e40488 100644 --- a/lib/rules/padding-line-between-statements.js +++ b/lib/rules/padding-line-between-statements.js @@ -253,7 +253,7 @@ function verifyForNever(context, _, nextNode, paddingLines) { const nextToken = paddingLines[0][1]; const start = prevToken.range[1]; const end = nextToken.range[0]; - const text = context.getSourceCode().text + const text = context.sourceCode.text .slice(start, end) .replace(PADDING_LINE_SEQUENCE, replacerToRemovePaddingLines); @@ -284,7 +284,7 @@ function verifyForAlways(context, prevNode, nextNode, paddingLines) { node: nextNode, messageId: "expectedBlankLine", fix(fixer) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let prevToken = getActualLastToken(sourceCode, prevNode); const nextToken = sourceCode.getFirstTokenBetween( prevToken, @@ -475,7 +475,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const configureList = context.options || []; let scopeInfo = null; diff --git a/lib/rules/prefer-arrow-callback.js b/lib/rules/prefer-arrow-callback.js index e7274142522..d22e508beb0 100644 --- a/lib/rules/prefer-arrow-callback.js +++ b/lib/rules/prefer-arrow-callback.js @@ -185,7 +185,7 @@ module.exports = { const allowUnboundThis = options.allowUnboundThis !== false; // default to true const allowNamedFunctions = options.allowNamedFunctions; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /* * {Array<{this: boolean, super: boolean, meta: boolean}>} diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js index 607824f61b6..b43975e9bae 100644 --- a/lib/rules/prefer-const.js +++ b/lib/rules/prefer-const.js @@ -356,7 +356,7 @@ module.exports = { create(context) { const options = context.options[0] || {}; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const shouldMatchAnyDestructuredVariable = options.destructuring !== "all"; const ignoreReadBeforeAssign = options.ignoreReadBeforeAssign === true; const variables = []; diff --git a/lib/rules/prefer-destructuring.js b/lib/rules/prefer-destructuring.js index 7ccc8c314d8..c6075c55bf5 100644 --- a/lib/rules/prefer-destructuring.js +++ b/lib/rules/prefer-destructuring.js @@ -190,7 +190,7 @@ module.exports = { */ function fixIntoObjectDestructuring(fixer, node) { const rightNode = node.init; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // Don't fix if that would remove any comments. Only comments inside `rightNode.object` can be preserved. if (sourceCode.getCommentsInside(node).length > sourceCode.getCommentsInside(rightNode.object).length) { diff --git a/lib/rules/prefer-exponentiation-operator.js b/lib/rules/prefer-exponentiation-operator.js index ec3a7c6c084..dd4ba2c8e04 100644 --- a/lib/rules/prefer-exponentiation-operator.js +++ b/lib/rules/prefer-exponentiation-operator.js @@ -104,7 +104,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports the given node. diff --git a/lib/rules/prefer-named-capture-group.js b/lib/rules/prefer-named-capture-group.js index e1a2b8af131..8fb68de1794 100644 --- a/lib/rules/prefer-named-capture-group.js +++ b/lib/rules/prefer-named-capture-group.js @@ -105,7 +105,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Function to check regular expression. diff --git a/lib/rules/prefer-numeric-literals.js b/lib/rules/prefer-numeric-literals.js index 60831bf50ef..118d6dce4e3 100644 --- a/lib/rules/prefer-numeric-literals.js +++ b/lib/rules/prefer-numeric-literals.js @@ -60,7 +60,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- // Public diff --git a/lib/rules/prefer-object-has-own.js b/lib/rules/prefer-object-has-own.js index 43964447f3b..97ea64fa673 100644 --- a/lib/rules/prefer-object-has-own.js +++ b/lib/rules/prefer-object-has-own.js @@ -62,7 +62,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { diff --git a/lib/rules/prefer-object-spread.js b/lib/rules/prefer-object-spread.js index a5abbabf9e8..60b0c3175c0 100644 --- a/lib/rules/prefer-object-spread.js +++ b/lib/rules/prefer-object-spread.js @@ -261,7 +261,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { Program(node) { diff --git a/lib/rules/prefer-promise-reject-errors.js b/lib/rules/prefer-promise-reject-errors.js index e8cadcdbaa5..e990265e99f 100644 --- a/lib/rules/prefer-promise-reject-errors.js +++ b/lib/rules/prefer-promise-reject-errors.js @@ -41,7 +41,7 @@ module.exports = { create(context) { const ALLOW_EMPTY_REJECT = context.options.length && context.options[0].allowEmptyReject; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //---------------------------------------------------------------------- // Helpers diff --git a/lib/rules/prefer-regex-literals.js b/lib/rules/prefer-regex-literals.js index 90ad3fbbc02..39e29506421 100644 --- a/lib/rules/prefer-regex-literals.js +++ b/lib/rules/prefer-regex-literals.js @@ -154,7 +154,7 @@ module.exports = { create(context) { const [{ disallowRedundantWrapping = false } = {}] = context.options; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether the given identifier node is a reference to a global variable. diff --git a/lib/rules/prefer-rest-params.js b/lib/rules/prefer-rest-params.js index c5ae7346f25..b7e35b40a72 100644 --- a/lib/rules/prefer-rest-params.js +++ b/lib/rules/prefer-rest-params.js @@ -79,7 +79,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports a given reference. diff --git a/lib/rules/prefer-spread.js b/lib/rules/prefer-spread.js index 1ecdaab2a25..7013c1d5052 100644 --- a/lib/rules/prefer-spread.js +++ b/lib/rules/prefer-spread.js @@ -63,7 +63,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { diff --git a/lib/rules/prefer-template.js b/lib/rules/prefer-template.js index d357e79776f..a2c8c724135 100644 --- a/lib/rules/prefer-template.js +++ b/lib/rules/prefer-template.js @@ -142,7 +142,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let done = Object.create(null); /** diff --git a/lib/rules/quote-props.js b/lib/rules/quote-props.js index 488f735294b..8abab150c4e 100644 --- a/lib/rules/quote-props.js +++ b/lib/rules/quote-props.js @@ -86,7 +86,7 @@ module.exports = { CHECK_UNNECESSARY = !context.options[1] || context.options[1].unnecessary !== false, NUMBERS = context.options[1] && context.options[1].numbers, - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; /** diff --git a/lib/rules/quotes.js b/lib/rules/quotes.js index d5d661cf1b0..9efb9809aa3 100644 --- a/lib/rules/quotes.js +++ b/lib/rules/quotes.js @@ -123,7 +123,7 @@ module.exports = { settings = QUOTE_SETTINGS[quoteOption || "double"], options = context.options[1], allowTemplateLiterals = options && options.allowTemplateLiterals === true, - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; let avoidEscape = options && options.avoidEscape === true; // deprecated diff --git a/lib/rules/radix.js b/lib/rules/radix.js index 445106952eb..7df97d98602 100644 --- a/lib/rules/radix.js +++ b/lib/rules/radix.js @@ -104,7 +104,7 @@ module.exports = { create(context) { const mode = context.options[0] || MODE_ALWAYS; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Checks the arguments of a given CallExpression node and reports it if it diff --git a/lib/rules/require-atomic-updates.js b/lib/rules/require-atomic-updates.js index e417362799e..ba369a203e7 100644 --- a/lib/rules/require-atomic-updates.js +++ b/lib/rules/require-atomic-updates.js @@ -198,7 +198,7 @@ module.exports = { create(context) { const allowProperties = !!context.options[0] && context.options[0].allowProperties; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const assignmentReferences = new Map(); const segmentInfo = new SegmentInfo(); let stack = null; diff --git a/lib/rules/require-await.js b/lib/rules/require-await.js index 573f7218ade..952dde5431f 100644 --- a/lib/rules/require-await.js +++ b/lib/rules/require-await.js @@ -47,7 +47,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; let scopeInfo = null; /** diff --git a/lib/rules/require-jsdoc.js b/lib/rules/require-jsdoc.js index 3202a68f7c4..b6fedf2289f 100644 --- a/lib/rules/require-jsdoc.js +++ b/lib/rules/require-jsdoc.js @@ -61,7 +61,7 @@ module.exports = { }, create(context) { - const source = context.getSourceCode(); + const source = context.sourceCode; const DEFAULT_OPTIONS = { FunctionDeclaration: true, MethodDefinition: false, diff --git a/lib/rules/require-unicode-regexp.js b/lib/rules/require-unicode-regexp.js index 6342f46e736..f748753a2d1 100644 --- a/lib/rules/require-unicode-regexp.js +++ b/lib/rules/require-unicode-regexp.js @@ -45,7 +45,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Literal[regex]"(node) { diff --git a/lib/rules/rest-spread-spacing.js b/lib/rules/rest-spread-spacing.js index 94bf4be423a..7791238081e 100644 --- a/lib/rules/rest-spread-spacing.js +++ b/lib/rules/rest-spread-spacing.js @@ -35,7 +35,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, alwaysSpace = context.options[0] === "always"; //-------------------------------------------------------------------------- diff --git a/lib/rules/semi-spacing.js b/lib/rules/semi-spacing.js index 52647030a9c..770f62d41f1 100644 --- a/lib/rules/semi-spacing.js +++ b/lib/rules/semi-spacing.js @@ -52,7 +52,7 @@ module.exports = { create(context) { const config = context.options[0], - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; let requireSpaceBefore = false, requireSpaceAfter = true; diff --git a/lib/rules/semi-style.js b/lib/rules/semi-style.js index f9a5de8b2c9..67ed1e478e7 100644 --- a/lib/rules/semi-style.js +++ b/lib/rules/semi-style.js @@ -87,7 +87,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const option = context.options[0] || "last"; /** diff --git a/lib/rules/semi.js b/lib/rules/semi.js index ac982b17f7c..6a473535d49 100644 --- a/lib/rules/semi.js +++ b/lib/rules/semi.js @@ -86,7 +86,7 @@ module.exports = { const exceptOneLine = Boolean(options && options.omitLastInOneLineBlock); const exceptOneLineClassBody = Boolean(options && options.omitLastInOneLineClassBody); const beforeStatementContinuationChars = options && options.beforeStatementContinuationChars || "any"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/sort-imports.js b/lib/rules/sort-imports.js index 89c1af7eb95..04814ed6fed 100644 --- a/lib/rules/sort-imports.js +++ b/lib/rules/sort-imports.js @@ -71,7 +71,7 @@ module.exports = { ignoreMemberSort = configuration.ignoreMemberSort || false, memberSyntaxSortOrder = configuration.memberSyntaxSortOrder || ["none", "all", "multiple", "single"], allowSeparatedGroups = configuration.allowSeparatedGroups || false, - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; let previousDeclaration = null; /** diff --git a/lib/rules/sort-keys.js b/lib/rules/sort-keys.js index e0cae69a638..088b5890f30 100644 --- a/lib/rules/sort-keys.js +++ b/lib/rules/sort-keys.js @@ -135,7 +135,7 @@ module.exports = { // The stack to save the previous property's name for each object literals. let stack = null; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { ObjectExpression(node) { diff --git a/lib/rules/sort-vars.js b/lib/rules/sort-vars.js index 318e402c923..8fd723fd4e5 100644 --- a/lib/rules/sort-vars.js +++ b/lib/rules/sort-vars.js @@ -44,7 +44,7 @@ module.exports = { const configuration = context.options[0] || {}, ignoreCase = configuration.ignoreCase || false, - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; return { VariableDeclaration(node) { diff --git a/lib/rules/space-before-blocks.js b/lib/rules/space-before-blocks.js index 7fd30456b27..a580a4f2249 100644 --- a/lib/rules/space-before-blocks.js +++ b/lib/rules/space-before-blocks.js @@ -80,7 +80,7 @@ module.exports = { create(context) { const config = context.options[0], - sourceCode = context.getSourceCode(); + sourceCode = context.sourceCode; let alwaysFunctions = true, alwaysKeywords = true, alwaysClasses = true, diff --git a/lib/rules/space-before-function-paren.js b/lib/rules/space-before-function-paren.js index 28b59bc31e0..c5faa8cf4dd 100644 --- a/lib/rules/space-before-function-paren.js +++ b/lib/rules/space-before-function-paren.js @@ -59,7 +59,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const baseConfig = typeof context.options[0] === "string" ? context.options[0] : "always"; const overrideConfig = typeof context.options[0] === "object" ? context.options[0] : {}; diff --git a/lib/rules/space-in-parens.js b/lib/rules/space-in-parens.js index fa56fee9811..c6c06d29a3f 100644 --- a/lib/rules/space-in-parens.js +++ b/lib/rules/space-in-parens.js @@ -102,7 +102,7 @@ module.exports = { //-------------------------------------------------------------------------- // Helpers //-------------------------------------------------------------------------- - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines if a token is one of the exceptions for the opener paren diff --git a/lib/rules/space-infix-ops.js b/lib/rules/space-infix-ops.js index ce48b1f2e7d..81a95f83bf2 100644 --- a/lib/rules/space-infix-ops.js +++ b/lib/rules/space-infix-ops.js @@ -43,7 +43,7 @@ module.exports = { create(context) { const int32Hint = context.options[0] ? context.options[0].int32Hint === true : false; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Returns the first token which violates the rule diff --git a/lib/rules/space-unary-ops.js b/lib/rules/space-unary-ops.js index 00aac6e2c4d..381381d6e5d 100644 --- a/lib/rules/space-unary-ops.js +++ b/lib/rules/space-unary-ops.js @@ -62,7 +62,7 @@ module.exports = { create(context) { const options = context.options[0] || { words: true, nonwords: false }; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; //-------------------------------------------------------------------------- // Helpers diff --git a/lib/rules/spaced-comment.js b/lib/rules/spaced-comment.js index 72c02f69d92..2eb7f0e3008 100644 --- a/lib/rules/spaced-comment.js +++ b/lib/rules/spaced-comment.js @@ -235,7 +235,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; // Unless the first option is never, require a space const requireSpace = context.options[0] !== "never"; diff --git a/lib/rules/switch-colon-spacing.js b/lib/rules/switch-colon-spacing.js index 8ea5d0cae66..45e401822a8 100644 --- a/lib/rules/switch-colon-spacing.js +++ b/lib/rules/switch-colon-spacing.js @@ -46,7 +46,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const options = context.options[0] || {}; const beforeSpacing = options.before === true; // false by default const afterSpacing = options.after !== false; // true by default diff --git a/lib/rules/symbol-description.js b/lib/rules/symbol-description.js index d2db188ec0a..4528f09cf6c 100644 --- a/lib/rules/symbol-description.js +++ b/lib/rules/symbol-description.js @@ -35,7 +35,7 @@ module.exports = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Reports if node does not conform the rule in case rule is set to diff --git a/lib/rules/template-curly-spacing.js b/lib/rules/template-curly-spacing.js index 2e7fb824031..cc9bbe306d5 100644 --- a/lib/rules/template-curly-spacing.js +++ b/lib/rules/template-curly-spacing.js @@ -40,7 +40,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const always = context.options[0] === "always"; /** diff --git a/lib/rules/template-tag-spacing.js b/lib/rules/template-tag-spacing.js index 68219ec1fad..9bfdfc2288d 100644 --- a/lib/rules/template-tag-spacing.js +++ b/lib/rules/template-tag-spacing.js @@ -33,7 +33,7 @@ module.exports = { create(context) { const never = context.options[0] !== "always"; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Check if a space is present between a template tag and its literal diff --git a/lib/rules/unicode-bom.js b/lib/rules/unicode-bom.js index 48eb538bdf5..09971d26e30 100644 --- a/lib/rules/unicode-bom.js +++ b/lib/rules/unicode-bom.js @@ -42,7 +42,7 @@ module.exports = { Program: function checkUnicodeBOM(node) { - const sourceCode = context.getSourceCode(), + const sourceCode = context.sourceCode, location = { column: 0, line: 1 }, requireBOM = context.options[0] || "never"; diff --git a/lib/rules/valid-jsdoc.js b/lib/rules/valid-jsdoc.js index 4d67dd3dd04..919975fe101 100644 --- a/lib/rules/valid-jsdoc.js +++ b/lib/rules/valid-jsdoc.js @@ -96,7 +96,7 @@ module.exports = { const options = context.options[0] || {}, prefer = options.prefer || {}, - sourceCode = context.getSourceCode(), + sourceCode = context.sourceCode, // these both default to true, so you have to explicitly make them false requireReturn = options.requireReturn !== false, diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js index ff9cc513e2b..82af130f98a 100644 --- a/lib/rules/valid-typeof.js +++ b/lib/rules/valid-typeof.js @@ -44,7 +44,7 @@ module.exports = { const VALID_TYPES = new Set(["symbol", "undefined", "object", "boolean", "number", "string", "function", "bigint"]), OPERATORS = new Set(["==", "===", "!=", "!=="]); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals; let globalScope; diff --git a/lib/rules/wrap-iife.js b/lib/rules/wrap-iife.js index 131d1517cda..4c448fa7993 100644 --- a/lib/rules/wrap-iife.js +++ b/lib/rules/wrap-iife.js @@ -77,7 +77,7 @@ module.exports = { const style = context.options[0] || "outside"; const includeFunctionPrototypeMethods = context.options[1] && context.options[1].functionPrototypeMethods; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Check if the node is wrapped in any (). All parens count: grouping parens and parens for constructs such as if() diff --git a/lib/rules/wrap-regex.js b/lib/rules/wrap-regex.js index 31d8bc7248e..8166c252f3c 100644 --- a/lib/rules/wrap-regex.js +++ b/lib/rules/wrap-regex.js @@ -29,7 +29,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { diff --git a/lib/rules/yield-star-spacing.js b/lib/rules/yield-star-spacing.js index de8c40ef3e4..9f9d918ae6c 100644 --- a/lib/rules/yield-star-spacing.js +++ b/lib/rules/yield-star-spacing.js @@ -48,7 +48,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const mode = (function(option) { if (!option || typeof option === "string") { diff --git a/lib/rules/yoda.js b/lib/rules/yoda.js index e3b0a0548f6..60a6ad2f2db 100644 --- a/lib/rules/yoda.js +++ b/lib/rules/yoda.js @@ -162,7 +162,7 @@ module.exports = { const onlyEquality = context.options[1] && context.options[1].onlyEquality; - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Determines whether node represents a range test. diff --git a/tests/fixtures/testers/rule-tester/no-test-global.js b/tests/fixtures/testers/rule-tester/no-test-global.js index 96c4c0790be..b44863d4278 100644 --- a/tests/fixtures/testers/rule-tester/no-test-global.js +++ b/tests/fixtures/testers/rule-tester/no-test-global.js @@ -16,7 +16,7 @@ module.exports = { }, create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { "Program"(node) { diff --git a/tests/fixtures/testers/rule-tester/no-var.js b/tests/fixtures/testers/rule-tester/no-var.js index 96a410fe78a..578b750c76e 100644 --- a/tests/fixtures/testers/rule-tester/no-var.js +++ b/tests/fixtures/testers/rule-tester/no-var.js @@ -15,7 +15,7 @@ module.exports = { schema: [] }, create(context) { - var sourceCode = context.getSourceCode(); + var sourceCode = context.sourceCode; return { "VariableDeclaration": function(node) { diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 13824c9da49..43a74f2579a 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -116,7 +116,8 @@ describe("Linter", () => { it("has all the `parent` properties on nodes when the rule listeners are created", () => { const spy = sinon.spy(context => { - const ast = context.getSourceCode().ast; + assert.strictEqual(context.getSourceCode(), context.sourceCode); + const ast = context.sourceCode.ast; assert.strictEqual(ast.body[0].parent, ast); assert.strictEqual(ast.body[0].expression.parent, ast.body[0]); @@ -3777,9 +3778,10 @@ var a = "test2"; create: context => ({ Program() { const scope = context.getScope(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const comments = sourceCode.getAllComments(); + assert.strictEqual(context.getSourceCode(), sourceCode); assert.strictEqual(1, comments.length); const foo = getVariable(scope, "foo"); @@ -5433,9 +5435,10 @@ var a = "test2"; create: context => ({ Program() { const scope = context.getScope(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const comments = sourceCode.getAllComments(); + assert.strictEqual(context.getSourceCode(), sourceCode); assert.strictEqual(2, comments.length); const foo = getVariable(scope, "foo"); @@ -6765,7 +6768,8 @@ var a = "test2"; receivedFilenames.push(context.filename); receivedPhysicalFilenames.push(context.physicalFilename); - context.report({ node: ast, message: context.getSourceCode().text }); + + context.report({ node: ast, message: context.sourceCode.text }); } }) }); @@ -7384,7 +7388,7 @@ var a = "test2"; }); linter.defineRule("save-scope-manager", { create(context) { - scopeManager = context.getSourceCode().scopeManager; + scopeManager = context.sourceCode.scopeManager; return {}; } @@ -8206,7 +8210,7 @@ describe("Linter with FlatConfigArray", () => { }, "save-scope-manager": { create(context) { - scopeManager = context.getSourceCode().scopeManager; + scopeManager = context.sourceCode.scopeManager; return {}; } @@ -8961,7 +8965,8 @@ describe("Linter with FlatConfigArray", () => { it("should have all the `parent` properties on nodes when the rule visitors are created", () => { const spy = sinon.spy(context => { - const ast = context.getSourceCode().ast; + assert.strictEqual(context.getSourceCode(), context.sourceCode); + const ast = context.sourceCode.ast; assert.strictEqual(ast.body[0].parent, ast); assert.strictEqual(ast.body[0].expression.parent, ast.body[0]); @@ -11613,9 +11618,10 @@ describe("Linter with FlatConfigArray", () => { create: context => ({ Program() { const scope = context.getScope(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const comments = sourceCode.getAllComments(); + assert.strictEqual(context.getSourceCode(), sourceCode); assert.strictEqual(2, comments.length); const foo = getVariable(scope, "foo"); @@ -13895,9 +13901,10 @@ var a = "test2"; create: context => ({ Program() { const scope = context.getScope(); - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const comments = sourceCode.getAllComments(); + assert.strictEqual(context.getSourceCode(), sourceCode); assert.strictEqual(1, comments.length); const foo = getVariable(scope, "foo"); @@ -15572,7 +15579,8 @@ var a = "test2"; receivedFilenames.push(context.filename); receivedPhysicalFilenames.push(context.physicalFilename); - context.report({ node: ast, message: context.getSourceCode().text }); + + context.report({ node: ast, message: context.sourceCode.text }); } }; } diff --git a/tests/lib/rule-tester/flat-rule-tester.js b/tests/lib/rule-tester/flat-rule-tester.js index c73099d1d54..f65c3bb1913 100644 --- a/tests/lib/rule-tester/flat-rule-tester.js +++ b/tests/lib/rule-tester/flat-rule-tester.js @@ -1447,7 +1447,7 @@ describe("FlatRuleTester", () => { const usesStartEndRule = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { @@ -2550,7 +2550,7 @@ describe("FlatRuleTester", () => { const useGetCommentsRule = { create: context => ({ Program(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; sourceCode.getComments(node); } diff --git a/tests/lib/rule-tester/rule-tester.js b/tests/lib/rule-tester/rule-tester.js index 096e639e95f..a36edafd409 100644 --- a/tests/lib/rule-tester/rule-tester.js +++ b/tests/lib/rule-tester/rule-tester.js @@ -1498,7 +1498,7 @@ describe("RuleTester", () => { const usesStartEndRule = { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { CallExpression(node) { @@ -2793,7 +2793,7 @@ describe("RuleTester", () => { const useGetCommentsRule = { create: context => ({ Program(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; sourceCode.getComments(node); } diff --git a/tests/lib/rules/comma-dangle.js b/tests/lib/rules/comma-dangle.js index da301dfcaef..49cd6c2546b 100644 --- a/tests/lib/rules/comma-dangle.js +++ b/tests/lib/rules/comma-dangle.js @@ -44,7 +44,7 @@ ruleTester.defineRule("add-named-import", { create(context) { return { ImportDeclaration(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const closingBrace = sourceCode.getLastToken(node, token => token.value === "}"); const addComma = sourceCode.getTokenBefore(closingBrace).value !== ","; diff --git a/tests/lib/rules/no-unused-vars.js b/tests/lib/rules/no-unused-vars.js index f35752227e0..3c1997b8468 100644 --- a/tests/lib/rules/no-unused-vars.js +++ b/tests/lib/rules/no-unused-vars.js @@ -21,7 +21,7 @@ const ruleTester = new RuleTester(); ruleTester.defineRule("use-every-a", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Mark a variable as used diff --git a/tests/lib/rules/prefer-const.js b/tests/lib/rules/prefer-const.js index c7837cee261..bd00484c99f 100644 --- a/tests/lib/rules/prefer-const.js +++ b/tests/lib/rules/prefer-const.js @@ -21,7 +21,7 @@ const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 6 } }); ruleTester.defineRule("use-x", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; return { VariableDeclaration(node) { diff --git a/tests/lib/source-code/source-code.js b/tests/lib/source-code/source-code.js index 9795aba86bf..dae9bcf4c3d 100644 --- a/tests/lib/source-code/source-code.js +++ b/tests/lib/source-code/source-code.js @@ -3032,7 +3032,7 @@ describe("SourceCode", () => { linter.defineRule("get-scope", { create: context => ({ Program() { - context.getSourceCode().getScope(); + context.sourceCode.getScope(); } }) }); @@ -3062,7 +3062,7 @@ describe("SourceCode", () => { create: context => ({ [astSelector](node0) { node = node0; - scope = context.getSourceCode().getScope(node); + scope = context.sourceCode.getScope(node); } }) }); @@ -3312,7 +3312,7 @@ describe("SourceCode", () => { checker: { create(context) { spy = sinon.spy(node => { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const ancestors = sourceCode.getAncestors(node); assert.strictEqual(ancestors.length, 3); @@ -3340,7 +3340,7 @@ describe("SourceCode", () => { checker: { create(context) { spy = sinon.spy(node => { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; const ancestors = sourceCode.getAncestors(node); assert.strictEqual(ancestors.length, 0); @@ -3369,7 +3369,7 @@ describe("SourceCode", () => { checker: { create(context) { spy = sinon.spy(() => { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; assert.throws(() => { sourceCode.getAncestors(); @@ -3406,7 +3406,7 @@ describe("SourceCode", () => { test: { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; /** * Assert `sourceCode.getDeclaredVariables(node)` is empty. @@ -3643,7 +3643,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; spy = sinon.spy(() => { assert.isTrue(sourceCode.markVariableAsUsed("a")); @@ -3668,7 +3668,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; spy = sinon.spy(node => { assert.isTrue(sourceCode.markVariableAsUsed("a", node)); @@ -3693,7 +3693,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; returnSpy = sinon.spy(node => { assert.isTrue(sourceCode.markVariableAsUsed("a", node)); @@ -3720,7 +3720,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; spy = sinon.spy(() => { const globalScope = context.getScope(), @@ -3746,7 +3746,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; spy = sinon.spy(() => { const globalScope = context.getScope(), @@ -3772,7 +3772,7 @@ describe("SourceCode", () => { linter.defineRule("checker", { create(context) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; spy = sinon.spy(() => { assert.isFalse(sourceCode.markVariableAsUsed("c")); diff --git a/tests/tools/eslint-fuzzer.js b/tests/tools/eslint-fuzzer.js index da267de24c1..2e372b04c45 100644 --- a/tests/tools/eslint-fuzzer.js +++ b/tests/tools/eslint-fuzzer.js @@ -52,7 +52,7 @@ describe("eslint-fuzzer", function() { linter.defineRule("test-fuzzer-rule", { create: context => ({ Program() { - if (context.getSourceCode().text === "foo") { + if (context.sourceCode.text === "foo") { throw CRASH_BUG; } } @@ -93,7 +93,7 @@ describe("eslint-fuzzer", function() { linter.defineRule("test-fuzzer-rule", { create: context => ({ Program() { - if (context.getSourceCode().text === "foo") { + if (context.sourceCode.text === "foo") { throw CRASH_BUG; } } @@ -118,7 +118,7 @@ describe("eslint-fuzzer", function() { meta: { fixable: "code" }, create: context => ({ Program(node) { - if (context.getSourceCode().text === `foo ${disableFixableRulesComment}`) { + if (context.sourceCode.text === `foo ${disableFixableRulesComment}`) { context.report({ node, message: "no foos allowed", @@ -153,7 +153,7 @@ describe("eslint-fuzzer", function() { meta: { fixable: "code" }, create: context => ({ Program(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (sourceCode.text === `foo ${disableFixableRulesComment}`) { context.report({ @@ -197,7 +197,7 @@ describe("eslint-fuzzer", function() { meta: { fixable: "code" }, create: context => ({ Program(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (sourceCode.text.startsWith("foo") || sourceCode.text === intermediateCode) { context.report({ @@ -245,7 +245,7 @@ describe("eslint-fuzzer", function() { meta: { fixable: "code" }, create: context => ({ Program(node) { - const sourceCode = context.getSourceCode(); + const sourceCode = context.sourceCode; if (sourceCode.text.startsWith("foo")) { context.report({