tools: update ESLint to 6.6.0

Update ESLint to 6.6.0

PR-URL: https://github.com/nodejs/node/pull/30123
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
cjihrig authored and Michaël Zasso committed 2019-10-31 11:34:48 +01:00
1 parent 07b5584a3f
commit d549a34597
258 files changed
+3029 -2632

No files matched your search

+4 -3
View File
@@ -40,7 +40,7 @@ ESLint is a tool for identifying and reporting on patterns found in ECMAScript/J
## <a name="installation-and-usage"></a>Installation and Usage
Prerequisites: [Node.js](https://nodejs.org/) (`^8.10.0`, `^10.13.0`, or `>=11.10.1`), npm version 3+.
Prerequisites: [Node.js](https://nodejs.org/) (`^8.10.0`, `^10.13.0`, or `>=11.10.1`) built with SSL support. (If you are using an official Node.js distribution, SSL is always built in.)
You can install ESLint using npm:
@@ -156,8 +156,9 @@ ESLint follows [semantic versioning](https://semver.org). However, due to the na
* A new CLI capability is created.
* New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
* A new formatter is created.
* `eslint:recommended` is updated and will result in strictly fewer errors (e.g., rule removals).
* Major release (likely to break your lint build)
* `eslint:recommended` is updated.
* `eslint:recommended` is updated and may result in new errors (e.g., rule additions, most rule option updates).
* A new option to an existing rule that results in ESLint reporting more errors by default.
* An existing formatter is removed.
* Part of the public API is removed or changed in an incompatible way.
@@ -264,7 +265,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
<h3>Gold Sponsors</h3>
<p><a href="https://www.shopify.com"><img src="https://images.opencollective.com/shopify/eeb91aa/logo.png" alt="Shopify" height="96"></a> <a href="http://engineering.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://badoo.com/team?utm_source=eslint"><img src="https://images.opencollective.com/badoo/2826a3b/logo.png" alt="Badoo" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://opensource.facebook.com"><img src="https://images.opencollective.com/fbopensource/fbb8a5b/logo.png" alt="Facebook Open Source" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/amp/c8a3b25/logo.png" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/0b37d14/logo.png" alt="Free Icons by Icons8" height="32"></a> <a href="https://uxplanet.org/top-ui-ux-design-agencies-user-experience-firms-8c54697e290"><img src="https://images.opencollective.com/ui-ux-design-agencies/cae5dfe/logo.png" alt="UI UX Design Agencies" height="32"></a> <a href="https://clay.global"><img src="https://images.opencollective.com/clayglobal/2468f34/logo.png" alt="clay" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/jsheroes1/9fedf0b/logo.png" alt="JSHeroes " height="32"></a></p>
<p><a href="https://uxplanet.org/top-ui-ux-design-agencies-user-experience-firms-8c54697e290"><img src="https://images.opencollective.com/ui-ux-design-agencies/cae5dfe/logo.png" alt="UI UX Design Agencies" height="32"></a> <a href="https://www.bugsnag.com/platforms?utm_source=Open Collective&utm_medium=Website&utm_content=open-source&utm_campaign=2019-community&utm_term="><img src="https://images.opencollective.com/bugsnag-stability-monitoring/c2cef36/logo.png" alt="Bugsnag Stability Monitoring" height="32"></a> <a href="https://www.minitool.com"><img src="https://images.opencollective.com/minitool-software-ltd/6d68e16/logo.png" alt="MiniTool Software Ltd" height="32"></a> <a href="https://www.codacy.com/?utm_source=eslint&utm_medium=cpm&utm_campaign=eslint-sponsorship"><img src="https://images.opencollective.com/codacy/ed22716/logo.png" alt="Codacy" height="32"></a> <a href="https://mixpanel.com"><img src="https://images.opencollective.com/mixpanel/cd682f7/logo.png" alt="Mixpanel" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/0b37d14/logo.png" alt="Free Icons by Icons8" height="32"></a> <a href="https://www.crosswordsolver.com"><img src="https://images.opencollective.com/crosswordsolver/d4481d6/logo.png" alt="Crosswordsolver" height="32"></a> <a href="https://clay.global"><img src="https://images.opencollective.com/clayglobal/2468f34/logo.png" alt="clay" height="32"></a> <a href="https://discordapp.com"><img src="https://images.opencollective.com/discordapp/7e3d9a9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://tekhattan.com"><img src="https://images.opencollective.com/tekhattan/bc73c28/logo.png" alt="TekHattan" height="32"></a> <a href="https://www.marfeel.com/"><img src="https://images.opencollective.com/marfeel/4b88e30/logo.png" alt="Marfeel" height="32"></a> <a href="http://www.firesticktricks.com"><img src="https://images.opencollective.com/fire-stick-tricks/b8fbe2c/logo.png" alt="Fire Stick Tricks" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/jsheroes1/9fedf0b/logo.png" alt="JSHeroes " height="32"></a></p>
<!--sponsorsend-->
## <a name="technology-sponsors"></a>Technology Sponsors
@@ -152,8 +152,9 @@ function createCLIConfigArray({
*/
class ConfigurationNotFoundError extends Error {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} directoryPath - The directory path.
* @param {string} directoryPath The directory path.
*/
constructor(directoryPath) {
super(`No ESLint configuration found in ${directoryPath}.`);
+9 -7
View File
@@ -145,7 +145,7 @@ function validateFixTypes(fixTypes) {
/**
* It will calculate the error and warning count for collection of messages per file
* @param {LintMessage[]} messages - Collection of messages
* @param {LintMessage[]} messages Collection of messages
* @returns {Object} Contains the stats
* @private
*/
@@ -173,7 +173,7 @@ function calculateStatsPerFile(messages) {
/**
* It will calculate the error and warning count for collection of results from all files
* @param {LintResult[]} results - Collection of messages from all the files
* @param {LintResult[]} results Collection of messages from all the files
* @returns {Object} Contains the stats
* @private
*/
@@ -272,8 +272,8 @@ function verifyText({
/**
* Returns result with warning by ignore settings
* @param {string} filePath - File path of checked code
* @param {string} baseDir - Absolute path of base directory
* @param {string} filePath File path of checked code
* @param {string} baseDir Absolute path of base directory
* @returns {LintResult} Result with single warning
* @private
*/
@@ -387,7 +387,6 @@ function isErrorMessage(message) {
* name will be the `cacheFile/.cache_hashOfCWD`
*
* if cacheFile points to a file or looks like a file then in will just use that file
*
* @param {string} cacheFile The name of file to be used to store the cache
* @param {string} cwd Current working directory
* @returns {string} the resolved path to the cache file
@@ -568,7 +567,7 @@ class CLIEngine {
});
const lintResultCache =
options.cache ? new LintResultCache(cacheFilePath) : null;
const linter = new Linter();
const linter = new Linter({ cwd: options.cwd });
/** @type {ConfigArray[]} */
const lastConfigArrays = [configArrayFactory.getConfigArrayForFile()];
@@ -668,11 +667,14 @@ class CLIEngine {
addPlugin(name, pluginObject) {
const {
additionalPluginPool,
configArrayFactory
configArrayFactory,
lastConfigArrays
} = internalSlotsMap.get(this);
additionalPluginPool.set(name, pluginObject);
configArrayFactory.clearCache();
lastConfigArrays.length = 1;
lastConfigArrays[0] = configArrayFactory.getConfigArrayForFile();
}
/**
+7 -1
View File
@@ -859,8 +859,14 @@ class ConfigArrayFactory {
if (filePath) {
try {
writeDebugLogForLoading(request, relativeTo, filePath);
const startTime = Date.now();
const pluginDefinition = require(filePath);
debug(`Plugin ${filePath} loaded in: ${Date.now() - startTime}ms`);
return new ConfigDependency({
definition: normalizePlugin(require(filePath)),
definition: normalizePlugin(pluginDefinition),
filePath,
id,
importerName,
@@ -126,7 +126,6 @@ function isNonNullObject(x) {
*
* Assign every property values of `y` to `x` if `x` doesn't have the property.
* If `x`'s property value is an object, it does recursive.
*
* @param {Object} target The destination to merge
* @param {Object|undefined} source The source to merge.
* @returns {void}
@@ -157,7 +156,6 @@ function mergeWithoutOverwrite(target, source) {
/**
* Merge plugins.
* `target`'s definition is prior to `source`'s.
*
* @param {Record<string, DependentPlugin>} target The destination to merge
* @param {Record<string, DependentPlugin>|undefined} source The source to merge.
* @returns {void}
@@ -187,7 +185,6 @@ function mergePlugins(target, source) {
/**
* Merge rule configs.
* `target`'s definition is prior to `source`'s.
*
* @param {Record<string, Array>} target The destination to merge
* @param {Record<string, RuleConf>|undefined} source The source to merge.
* @returns {void}
@@ -382,7 +379,6 @@ function ensurePluginMemberMaps(instance) {
* You need to call `ConfigArray#extractConfig(filePath)` method in order to
* extract, merge and get only the config data which is related to an arbitrary
* file.
*
* @extends {Array<ConfigArrayElement>}
*/
class ConfigArray extends Array {
@@ -81,6 +81,7 @@ class ConfigDependency {
this.importerPath = importerPath;
}
// eslint-disable-next-line jsdoc/require-description
/**
* @returns {Object} a JSON compatible object.
*/
@@ -95,6 +96,7 @@ class ConfigDependency {
return obj;
}
// eslint-disable-next-line jsdoc/require-description
/**
* @returns {Object} an object to display by `console.log()`.
*/
@@ -166,6 +166,7 @@ class OverrideTester {
));
}
// eslint-disable-next-line jsdoc/require-description
/**
* @returns {Object} a JSON compatible object.
*/
@@ -182,6 +183,7 @@ class OverrideTester {
};
}
// eslint-disable-next-line jsdoc/require-description
/**
* @returns {Object} an object to display by `console.log()`.
*/
+5 -3
View File
@@ -149,9 +149,10 @@ function readdirSafeSync(directoryPath) {
*/
class NoFilesFoundError extends Error {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} pattern - The glob pattern which was not found.
* @param {boolean} globDisabled - If `true` then the pattern was a glob pattern, but glob was disabled.
* @param {string} pattern The glob pattern which was not found.
* @param {boolean} globDisabled If `true` then the pattern was a glob pattern, but glob was disabled.
*/
constructor(pattern, globDisabled) {
super(`No files matching '${pattern}' were found${globDisabled ? " (glob was disabled)" : ""}.`);
@@ -165,8 +166,9 @@ class NoFilesFoundError extends Error {
*/
class AllFilesIgnoredError extends Error {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} pattern - The glob pattern which was not found.
* @param {string} pattern The glob pattern which was not found.
*/
constructor(pattern) {
super(`All files matched by '${pattern}' are ignored.`);
+1
View File
@@ -96,6 +96,7 @@ function renderMessages(messages, parentIndex, rulesMeta) {
}).join("\n");
}
// eslint-disable-next-line jsdoc/require-description
/**
* @param {Array} results Test results.
* @param {Object} rulesMeta Dictionary containing metadata for each rule executed by the analysis.
+1
View File
@@ -121,6 +121,7 @@ function relativize(globPattern, relativePathToOldBaseDir) {
*/
class IgnoredPaths {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {Object} providedOptions object containing 'ignore', 'ignorePath' and 'patterns' properties
*/
+1 -11
View File
@@ -31,7 +31,6 @@ const MAX_CONFIG_COMBINATIONS = 17, // 16 combinations + 1 for severity only
/**
* Information about a rule configuration, in the context of a Registry.
*
* @typedef {Object} registryItem
* @param {ruleConfig} config A valid configuration for the rule
* @param {number} specificity The number of elements in the ruleConfig array
@@ -70,6 +69,7 @@ function makeRegistryItems(rulesConfig) {
*/
class Registry {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {rulesConfig} [rulesConfig] Hash of rule names and arrays of possible configurations
*/
@@ -82,7 +82,6 @@ class Registry {
*
* It will set the registry's `rule` property to an object having rule names
* as keys and an array of registryItems as values.
*
* @returns {void}
*/
populateFromCoreRules() {
@@ -101,7 +100,6 @@ class Registry {
* configurations.
*
* The length of the returned array will be <= MAX_CONFIG_COMBINATIONS.
*
* @returns {Object[]} "rules" configurations to use for linting
*/
buildRuleSets() {
@@ -114,7 +112,6 @@ class Registry {
*
* This is broken out into its own function so that it doesn't need to be
* created inside of the while loop.
*
* @param {string} rule The ruleId to add.
* @returns {void}
*/
@@ -162,7 +159,6 @@ class Registry {
*
* Note: this also removes rule configurations which were not linted
* (meaning, they have an undefined errorCount).
*
* @returns {void}
*/
stripFailingConfigs() {
@@ -185,7 +181,6 @@ class Registry {
/**
* Removes rule configurations which were not included in a ruleSet
*
* @returns {void}
*/
stripExtraConfigs() {
@@ -204,7 +199,6 @@ class Registry {
* Creates a registry of rules which had no error-free configs.
* The new registry is intended to be analyzed to determine whether its rules
* should be disabled or set to warning.
*
* @returns {Registry} A registry of failing rules.
*/
getFailingRulesRegistry() {
@@ -225,7 +219,6 @@ class Registry {
/**
* Create an eslint config for any rules which only have one configuration
* in the registry.
*
* @returns {Object} An eslint config with rules section populated
*/
createConfig() {
@@ -243,7 +236,6 @@ class Registry {
/**
* Return a cloned registry containing only configs with a desired specificity
*
* @param {number} specificity Only keep configs with this specificity
* @returns {Registry} A registry of rules
*/
@@ -261,7 +253,6 @@ class Registry {
/**
* Lint SourceCodes against all configurations in the registry, and record results
*
* @param {Object[]} sourceCodes SourceCode objects for each filename
* @param {Object} config ESLint config object
* @param {progressCallback} [cb] Optional callback for reporting execution status
@@ -327,7 +318,6 @@ class Registry {
*
* This will return a new config with `"extends": "eslint:recommended"` and
* only the rules which have configurations different from the recommended config.
*
* @param {Object} config config object
* @returns {Object} config object using `"extends": "eslint:recommended"`
*/
-1
View File
@@ -23,7 +23,6 @@ const debug = require("debug")("eslint:config-file");
* Determines sort order for object keys for json-stable-stringify
*
* see: https://github.com/samn/json-stable-stringify#cmp
*
* @param {Object} a The first comparison object ({key: akey, value: avalue})
* @param {Object} b The second comparison object ({key: bkey, value: bvalue})
* @returns {number} 1 or -1, used in stringify cmp method
-1
View File
@@ -147,7 +147,6 @@ function getModulesList(config, installESLint) {
*
* Note: This clones the config object and returns a new config to avoid mutating
* the original config parameter.
*
* @param {Object} answers answers received from inquirer
* @param {Object} config config object
* @returns {Object} config object with configured rules
+1 -5
View File
@@ -33,7 +33,6 @@ function explodeArray(xs) {
*
* For example:
* combineArrays([a, [b, c]], [x, y]); // -> [[a, x], [a, y], [b, c, x], [b, c, y]]
*
* @param {Array} arr1 The first array to combine.
* @param {Array} arr2 The second array to combine.
* @returns {Array} A mixture of the elements of the first and second arrays.
@@ -71,7 +70,6 @@ function combineArrays(arr1, arr2) {
* [{before: true}, {before: false}],
* [{after: true}, {after: false}]
* ]
*
* @param {Object[]} objects Array of objects, each with one property/value pair
* @returns {Array[]} Array of arrays of objects grouped by property
*/
@@ -98,7 +96,6 @@ function groupByProperty(objects) {
* element in the array is the severity, and is the only required element.
* Configs may also have one or more additional elements to specify rule
* configuration or options.
*
* @typedef {Array|number} ruleConfig
* @param {number} 0 The rule's severity (0, 1, 2).
*/
@@ -134,7 +131,6 @@ function groupByProperty(objects) {
* {before: false, after: true},
* {before: false, after: false}
* ]
*
* @param {Object[]} objArr1 Single key/value objects, all with the same key
* @param {Object[]} objArr2 Single key/value objects, all with another key
* @returns {Object[]} Combined objects for each combination of input properties and values
@@ -178,6 +174,7 @@ function combinePropertyObjects(objArr1, objArr2) {
*/
class RuleConfigSet {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {ruleConfig[]} configs Valid rule configurations
*/
@@ -193,7 +190,6 @@ class RuleConfigSet {
/**
* Add a severity level to the front of all configs in the instance.
* This should only be called after all configs have been added to the instance.
*
* @returns {void}
*/
addErrorSeverity() {
-5
View File
@@ -21,7 +21,6 @@ const fs = require("fs"),
/**
* Find the closest package.json file, starting at process.cwd (by default),
* and working up to root.
*
* @param {string} [startDir=process.cwd()] Starting directory
* @returns {string} Absolute path to closest package.json file
*/
@@ -88,7 +87,6 @@ function fetchPeerDependencies(packageName) {
/**
* Check whether node modules are include in a project's package.json.
*
* @param {string[]} packages Array of node module names
* @param {Object} opt Options Object
* @param {boolean} opt.dependencies Set to true to check for direct dependencies
@@ -136,7 +134,6 @@ function check(packages, opt) {
* package.json.
*
* Convenience wrapper around check().
*
* @param {string[]} packages Array of node modules to check.
* @param {string} rootDir The directory contianing a package.json
* @returns {Object} An object whose keys are the module names
@@ -151,7 +148,6 @@ function checkDeps(packages, rootDir) {
* package.json.
*
* Convenience wrapper around check().
*
* @param {string[]} packages Array of node modules to check.
* @returns {Object} An object whose keys are the module names
* and values are booleans indicating installation.
@@ -162,7 +158,6 @@ function checkDevDeps(packages) {
/**
* Check whether package.json is found in current path.
*
* @param {string} [startDir] Starting directory
* @returns {boolean} Whether a package.json is found in current path.
*/
@@ -22,8 +22,7 @@ const assert = require("assert"),
/**
* Checks whether or not a given node is a `case` node (not `default` node).
*
* @param {ASTNode} node - A `SwitchCase` node to check.
* @param {ASTNode} node A `SwitchCase` node to check.
* @returns {boolean} `true` if the node is a `case` node (not `default` node).
*/
function isCaseNode(node) {
@@ -33,8 +32,7 @@ function isCaseNode(node) {
/**
* Checks whether the given logical operator is taken into account for the code
* path analysis.
*
* @param {string} operator - The operator found in the LogicalExpression node
* @param {string} operator The operator found in the LogicalExpression node
* @returns {boolean} `true` if the operator is "&&" or "||"
*/
function isHandledLogicalOperator(operator) {
@@ -43,8 +41,7 @@ function isHandledLogicalOperator(operator) {
/**
* Gets the label if the parent node of a given node is a LabeledStatement.
*
* @param {ASTNode} node - A node to get.
* @param {ASTNode} node A node to get.
* @returns {string|null} The label or `null`.
*/
function getLabel(node) {
@@ -57,8 +54,7 @@ function getLabel(node) {
/**
* Checks whether or not a given logical expression node goes different path
* between the `true` case and the `false` case.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is a test of a choice statement.
*/
function isForkingByTrueOrFalse(node) {
@@ -86,8 +82,7 @@ function isForkingByTrueOrFalse(node) {
* This is used to detect infinity loops (e.g. `while (true) {}`).
* Statements preceded by an infinity loop are unreachable if the loop didn't
* have any `break` statement.
*
* @param {ASTNode} node - A node to get.
* @param {ASTNode} node A node to get.
* @returns {boolean|undefined} a boolean value if the node is a Literal node,
* otherwise `undefined`.
*/
@@ -102,8 +97,7 @@ function getBooleanValueIfSimpleConstant(node) {
* Checks that a given identifier node is a reference or not.
*
* This is used to detect the first throwable node in a `try` block.
*
* @param {ASTNode} node - An Identifier node to check.
* @param {ASTNode} node An Identifier node to check.
* @returns {boolean} `true` if the node is a reference.
*/
function isIdentifierReference(node) {
@@ -153,9 +147,8 @@ function isIdentifierReference(node) {
*
* In this process, both "onCodePathSegmentStart" and "onCodePathSegmentEnd"
* events are fired.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function forwardCurrentToHead(analyzer, node) {
@@ -211,9 +204,8 @@ function forwardCurrentToHead(analyzer, node) {
/**
* Updates the current segment with empty.
* This is called at the last of functions or the program.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function leaveFromCurrentSegment(analyzer, node) {
@@ -242,9 +234,8 @@ function leaveFromCurrentSegment(analyzer, node) {
*
* For example, if the node is `parent.consequent`, this creates a fork from the
* current path.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function preprocess(analyzer, node) {
@@ -352,9 +343,8 @@ function preprocess(analyzer, node) {
/**
* Updates the code path due to the type of a given node in entering.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function processCodePathToEnter(analyzer, node) {
@@ -449,9 +439,8 @@ function processCodePathToEnter(analyzer, node) {
/**
* Updates the code path due to the type of a given node in leaving.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function processCodePathToExit(analyzer, node) {
@@ -563,9 +552,8 @@ function processCodePathToExit(analyzer, node) {
/**
* Updates the code path to finalize the current code path.
*
* @param {CodePathAnalyzer} analyzer - The instance.
* @param {ASTNode} node - The current AST node.
* @param {CodePathAnalyzer} analyzer The instance.
* @param {ASTNode} node The current AST node.
* @returns {void}
*/
function postprocess(analyzer, node) {
@@ -609,8 +597,9 @@ function postprocess(analyzer, node) {
*/
class CodePathAnalyzer {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {EventGenerator} eventGenerator - An event generator to wrap.
* @param {EventGenerator} eventGenerator An event generator to wrap.
*/
constructor(eventGenerator) {
this.original = eventGenerator;
@@ -624,8 +613,7 @@ class CodePathAnalyzer {
/**
* Does the process to enter a given AST node.
* This updates state of analysis and calls `enterNode` of the wrapped.
*
* @param {ASTNode} node - A node which is entering.
* @param {ASTNode} node A node which is entering.
* @returns {void}
*/
enterNode(node) {
@@ -651,8 +639,7 @@ class CodePathAnalyzer {
/**
* Does the process to leave a given AST node.
* This updates state of analysis and calls `leaveNode` of the wrapped.
*
* @param {ASTNode} node - A node which is leaving.
* @param {ASTNode} node A node which is leaving.
* @returns {void}
*/
leaveNode(node) {
@@ -676,9 +663,8 @@ class CodePathAnalyzer {
/**
* This is called on a code path looped.
* Then this raises a looped event.
*
* @param {CodePathSegment} fromSegment - A segment of prev.
* @param {CodePathSegment} toSegment - A segment of next.
* @param {CodePathSegment} fromSegment A segment of prev.
* @param {CodePathSegment} toSegment A segment of next.
* @returns {void}
*/
onLooped(fromSegment, toSegment) {
+17 -25
View File
@@ -17,8 +17,7 @@ const debug = require("./debug-helpers");
/**
* Checks whether or not a given segment is reachable.
*
* @param {CodePathSegment} segment - A segment to check.
* @param {CodePathSegment} segment A segment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -34,11 +33,12 @@ function isReachable(segment) {
*/
class CodePathSegment {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} id - An identifier.
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
* @param {string} id An identifier.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
* This array includes unreachable segments.
* @param {boolean} reachable - A flag which shows this is reachable.
* @param {boolean} reachable A flag which shows this is reachable.
*/
constructor(id, allPrevSegments, reachable) {
@@ -98,8 +98,7 @@ class CodePathSegment {
/**
* Checks a given previous segment is coming from the end of a loop.
*
* @param {CodePathSegment} segment - A previous segment to check.
* @param {CodePathSegment} segment A previous segment to check.
* @returns {boolean} `true` if the segment is coming from the end of a loop.
*/
isLoopedPrevSegment(segment) {
@@ -108,8 +107,7 @@ class CodePathSegment {
/**
* Creates the root segment.
*
* @param {string} id - An identifier.
* @param {string} id An identifier.
* @returns {CodePathSegment} The created segment.
*/
static newRoot(id) {
@@ -118,9 +116,8 @@ class CodePathSegment {
/**
* Creates a segment that follows given segments.
*
* @param {string} id - An identifier.
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
* @param {string} id An identifier.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
* @returns {CodePathSegment} The created segment.
*/
static newNext(id, allPrevSegments) {
@@ -133,9 +130,8 @@ class CodePathSegment {
/**
* Creates an unreachable segment that follows given segments.
*
* @param {string} id - An identifier.
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
* @param {string} id An identifier.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
* @returns {CodePathSegment} The created segment.
*/
static newUnreachable(id, allPrevSegments) {
@@ -154,9 +150,8 @@ class CodePathSegment {
* Creates a segment that follows given segments.
* This factory method does not connect with `allPrevSegments`.
* But this inherits `reachable` flag.
*
* @param {string} id - An identifier.
* @param {CodePathSegment[]} allPrevSegments - An array of the previous segments.
* @param {string} id An identifier.
* @param {CodePathSegment[]} allPrevSegments An array of the previous segments.
* @returns {CodePathSegment} The created segment.
*/
static newDisconnected(id, allPrevSegments) {
@@ -167,8 +162,7 @@ class CodePathSegment {
* Makes a given segment being used.
*
* And this function registers the segment into the previous segments as a next.
*
* @param {CodePathSegment} segment - A segment to mark.
* @param {CodePathSegment} segment A segment to mark.
* @returns {void}
*/
static markUsed(segment) {
@@ -195,9 +189,8 @@ class CodePathSegment {
/**
* Marks a previous segment as looped.
*
* @param {CodePathSegment} segment - A segment.
* @param {CodePathSegment} prevSegment - A previous segment to mark.
* @param {CodePathSegment} segment A segment.
* @param {CodePathSegment} prevSegment A previous segment to mark.
* @returns {void}
*/
static markPrevSegmentAsLooped(segment, prevSegment) {
@@ -206,8 +199,7 @@ class CodePathSegment {
/**
* Replaces unused segments with the previous segments of each unused segment.
*
* @param {CodePathSegment[]} segments - An array of segments to replace.
* @param {CodePathSegment[]} segments An array of segments to replace.
* @returns {CodePathSegment[]} The replaced array.
*/
static flattenUnusedSegments(segments) {
+40 -81
View File
@@ -22,11 +22,10 @@ const CodePathSegment = require("./code-path-segment"),
* array as well.
*
* This adds only reachable and used segments.
*
* @param {CodePathSegment[]} dest - A destination array (`returnedSegments` or `thrownSegments`).
* @param {CodePathSegment[]} others - Another destination array (`returnedSegments` or `thrownSegments`).
* @param {CodePathSegment[]} all - The unified destination array (`finalSegments`).
* @param {CodePathSegment[]} segments - Segments to add.
* @param {CodePathSegment[]} dest A destination array (`returnedSegments` or `thrownSegments`).
* @param {CodePathSegment[]} others Another destination array (`returnedSegments` or `thrownSegments`).
* @param {CodePathSegment[]} all The unified destination array (`finalSegments`).
* @param {CodePathSegment[]} segments Segments to add.
* @returns {void}
*/
function addToReturnedOrThrown(dest, others, all, segments) {
@@ -42,9 +41,8 @@ function addToReturnedOrThrown(dest, others, all, segments) {
/**
* Gets a loop-context for a `continue` statement.
*
* @param {CodePathState} state - A state to get.
* @param {string} label - The label of a `continue` statement.
* @param {CodePathState} state A state to get.
* @param {string} label The label of a `continue` statement.
* @returns {LoopContext} A loop-context for a `continue` statement.
*/
function getContinueContext(state, label) {
@@ -67,9 +65,8 @@ function getContinueContext(state, label) {
/**
* Gets a context for a `break` statement.
*
* @param {CodePathState} state - A state to get.
* @param {string} label - The label of a `break` statement.
* @param {CodePathState} state A state to get.
* @param {string} label The label of a `break` statement.
* @returns {LoopContext|SwitchContext} A context for a `break` statement.
*/
function getBreakContext(state, label) {
@@ -88,8 +85,7 @@ function getBreakContext(state, label) {
/**
* Gets a context for a `return` statement.
*
* @param {CodePathState} state - A state to get.
* @param {CodePathState} state A state to get.
* @returns {TryContext|CodePathState} A context for a `return` statement.
*/
function getReturnContext(state) {
@@ -107,8 +103,7 @@ function getReturnContext(state) {
/**
* Gets a context for a `throw` statement.
*
* @param {CodePathState} state - A state to get.
* @param {CodePathState} state A state to get.
* @returns {TryContext|CodePathState} A context for a `throw` statement.
*/
function getThrowContext(state) {
@@ -128,9 +123,8 @@ function getThrowContext(state) {
/**
* Removes a given element from a given array.
*
* @param {any[]} xs - An array to remove the specific element.
* @param {any} x - An element to be removed.
* @param {any[]} xs An array to remove the specific element.
* @param {any} x An element to be removed.
* @returns {void}
*/
function remove(xs, x) {
@@ -143,9 +137,8 @@ function remove(xs, x) {
* This is used in a process for switch statements.
* If there is the "default" chunk before other cases, the order is different
* between node's and running's.
*
* @param {CodePathSegment[]} prevSegments - Forward segments to disconnect.
* @param {CodePathSegment[]} nextSegments - Backward segments to disconnect.
* @param {CodePathSegment[]} prevSegments Forward segments to disconnect.
* @param {CodePathSegment[]} nextSegments Backward segments to disconnect.
* @returns {void}
*/
function removeConnection(prevSegments, nextSegments) {
@@ -162,10 +155,9 @@ function removeConnection(prevSegments, nextSegments) {
/**
* Creates looping path.
*
* @param {CodePathState} state - The instance.
* @param {CodePathSegment[]} unflattenedFromSegments - Segments which are source.
* @param {CodePathSegment[]} unflattenedToSegments - Segments which are destination.
* @param {CodePathState} state The instance.
* @param {CodePathSegment[]} unflattenedFromSegments Segments which are source.
* @param {CodePathSegment[]} unflattenedToSegments Segments which are destination.
* @returns {void}
*/
function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
@@ -200,10 +192,9 @@ function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
*
* - Adds `false` paths to paths which are leaving from the loop.
* - Sets `true` paths to paths which go to the body.
*
* @param {LoopContext} context - A loop context to modify.
* @param {ChoiceContext} choiceContext - A choice context of this loop.
* @param {CodePathSegment[]} head - The current head paths.
* @param {LoopContext} context A loop context to modify.
* @param {ChoiceContext} choiceContext A choice context of this loop.
* @param {CodePathSegment[]} head The current head paths.
* @returns {void}
*/
function finalizeTestSegmentsOfFor(context, choiceContext, head) {
@@ -227,10 +218,11 @@ function finalizeTestSegmentsOfFor(context, choiceContext, head) {
*/
class CodePathState {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {IdGenerator} idGenerator - An id generator to generate id for code
* @param {IdGenerator} idGenerator An id generator to generate id for code
* path segments.
* @param {Function} onLooped - A callback function to notify looping.
* @param {Function} onLooped A callback function to notify looping.
*/
constructor(idGenerator, onLooped) {
this.idGenerator = idGenerator;
@@ -275,8 +267,7 @@ class CodePathState {
/**
* Creates and stacks new forking context.
*
* @param {boolean} forkLeavingPath - A flag which shows being in a
* @param {boolean} forkLeavingPath A flag which shows being in a
* "finally" block.
* @returns {ForkContext} The created context.
*/
@@ -313,7 +304,6 @@ class CodePathState {
/**
* Creates a bypass path.
* This is used for such as IfStatement which does not have "else" chunk.
*
* @returns {void}
*/
forkBypassPath() {
@@ -346,12 +336,11 @@ class CodePathState {
* a -> foo();
* a -> b -> foo();
* a -> b -> bar();
*
* @param {string} kind - A kind string.
* @param {string} kind A kind string.
* If the new context is LogicalExpression's, this is `"&&"` or `"||"`.
* If it's IfStatement's or ConditionalExpression's, this is `"test"`.
* Otherwise, this is `"loop"`.
* @param {boolean} isForkingAsResult - A flag that shows that goes different
* @param {boolean} isForkingAsResult A flag that shows that goes different
* paths between `true` and `false`.
* @returns {void}
*/
@@ -368,7 +357,6 @@ class CodePathState {
/**
* Pops the last choice context and finalizes it.
*
* @returns {ChoiceContext} The popped context.
*/
popChoiceContext() {
@@ -456,7 +444,6 @@ class CodePathState {
/**
* Makes a code path segment of the right-hand operand of a logical
* expression.
*
* @returns {void}
*/
makeLogicalRight() {
@@ -500,7 +487,6 @@ class CodePathState {
/**
* Makes a code path segment of the `if` block.
*
* @returns {void}
*/
makeIfConsequent() {
@@ -527,7 +513,6 @@ class CodePathState {
/**
* Makes a code path segment of the `else` block.
*
* @returns {void}
*/
makeIfAlternate() {
@@ -554,10 +539,9 @@ class CodePathState {
/**
* Creates a context object of SwitchStatement and stacks it.
*
* @param {boolean} hasCase - `true` if the switch statement has one or more
* @param {boolean} hasCase `true` if the switch statement has one or more
* case parts.
* @param {string|null} label - The label text.
* @param {string|null} label The label text.
* @returns {void}
*/
pushSwitchContext(hasCase, label) {
@@ -581,7 +565,6 @@ class CodePathState {
* - Creates the next code path segment from `context.brokenForkContext`.
* - If the last `SwitchCase` node is not a `default` part, creates a path
* to the `default` body.
*
* @returns {void}
*/
popSwitchContext() {
@@ -655,9 +638,8 @@ class CodePathState {
/**
* Makes a code path segment for a `SwitchCase` node.
*
* @param {boolean} isEmpty - `true` if the body is empty.
* @param {boolean} isDefault - `true` if the body is the default case.
* @param {boolean} isEmpty `true` if the body is empty.
* @param {boolean} isDefault `true` if the body is the default case.
* @returns {void}
*/
makeSwitchCaseBody(isEmpty, isDefault) {
@@ -706,8 +688,7 @@ class CodePathState {
/**
* Creates a context object of TryStatement and stacks it.
*
* @param {boolean} hasFinalizer - `true` if the try statement has a
* @param {boolean} hasFinalizer `true` if the try statement has a
* `finally` block.
* @returns {void}
*/
@@ -729,7 +710,6 @@ class CodePathState {
/**
* Pops the last context of TryStatement and finalizes it.
*
* @returns {void}
*/
popTryContext() {
@@ -785,7 +765,6 @@ class CodePathState {
/**
* Makes a code path segment for a `catch` block.
*
* @returns {void}
*/
makeCatchBlock() {
@@ -814,7 +793,6 @@ class CodePathState {
* In the `finally` block, parallel paths are created. The parallel paths
* are used as leaving-paths. The leaving-paths are paths from `return`
* statements and `throw` statements in a `try` block or a `catch` block.
*
* @returns {void}
*/
makeFinallyBlock() {
@@ -874,7 +852,6 @@ class CodePathState {
/**
* Makes a code path segment from the first throwable node to the `catch`
* block or the `finally` block.
*
* @returns {void}
*/
makeFirstThrowablePathInTryBlock() {
@@ -903,11 +880,10 @@ class CodePathState {
/**
* Creates a context object of a loop statement and stacks it.
*
* @param {string} type - The type of the node which was triggered. One of
* @param {string} type The type of the node which was triggered. One of
* `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`,
* and `ForStatement`.
* @param {string|null} label - A label of the node which was triggered.
* @param {string|null} label A label of the node which was triggered.
* @returns {void}
*/
pushLoopContext(type, label) {
@@ -979,7 +955,6 @@ class CodePathState {
/**
* Pops the last context of a loop statement and finalizes it.
*
* @returns {void}
*/
popLoopContext() {
@@ -1051,8 +1026,7 @@ class CodePathState {
/**
* Makes a code path segment for the test part of a WhileStatement.
*
* @param {boolean|undefined} test - The test value (only when constant).
* @param {boolean|undefined} test The test value (only when constant).
* @returns {void}
*/
makeWhileTest(test) {
@@ -1068,7 +1042,6 @@ class CodePathState {
/**
* Makes a code path segment for the body part of a WhileStatement.
*
* @returns {void}
*/
makeWhileBody() {
@@ -1090,7 +1063,6 @@ class CodePathState {
/**
* Makes a code path segment for the body part of a DoWhileStatement.
*
* @returns {void}
*/
makeDoWhileBody() {
@@ -1105,8 +1077,7 @@ class CodePathState {
/**
* Makes a code path segment for the test part of a DoWhileStatement.
*
* @param {boolean|undefined} test - The test value (only when constant).
* @param {boolean|undefined} test The test value (only when constant).
* @returns {void}
*/
makeDoWhileTest(test) {
@@ -1126,8 +1097,7 @@ class CodePathState {
/**
* Makes a code path segment for the test part of a ForStatement.
*
* @param {boolean|undefined} test - The test value (only when constant).
* @param {boolean|undefined} test The test value (only when constant).
* @returns {void}
*/
makeForTest(test) {
@@ -1145,7 +1115,6 @@ class CodePathState {
/**
* Makes a code path segment for the update part of a ForStatement.
*
* @returns {void}
*/
makeForUpdate() {
@@ -1173,7 +1142,6 @@ class CodePathState {
/**
* Makes a code path segment for the body part of a ForStatement.
*
* @returns {void}
*/
makeForBody() {
@@ -1227,7 +1195,6 @@ class CodePathState {
/**
* Makes a code path segment for the left part of a ForInStatement and a
* ForOfStatement.
*
* @returns {void}
*/
makeForInOfLeft() {
@@ -1244,7 +1211,6 @@ class CodePathState {
/**
* Makes a code path segment for the right part of a ForInStatement and a
* ForOfStatement.
*
* @returns {void}
*/
makeForInOfRight() {
@@ -1263,7 +1229,6 @@ class CodePathState {
/**
* Makes a code path segment for the body part of a ForInStatement and a
* ForOfStatement.
*
* @returns {void}
*/
makeForInOfBody() {
@@ -1288,10 +1253,9 @@ class CodePathState {
/**
* Creates new context for BreakStatement.
*
* @param {boolean} breakable - The flag to indicate it can break by
* @param {boolean} breakable The flag to indicate it can break by
* an unlabeled BreakStatement.
* @param {string|null} label - The label of this context.
* @param {string|null} label The label of this context.
* @returns {Object} The new context.
*/
pushBreakContext(breakable, label) {
@@ -1306,7 +1270,6 @@ class CodePathState {
/**
* Removes the top item of the break context stack.
*
* @returns {Object} The removed context.
*/
popBreakContext() {
@@ -1333,8 +1296,7 @@ class CodePathState {
*
* It registers the head segment to a context of `break`.
* It makes new unreachable segment, then it set the head with the segment.
*
* @param {string} label - A label of the break statement.
* @param {string} label A label of the break statement.
* @returns {void}
*/
makeBreak(label) {
@@ -1359,8 +1321,7 @@ class CodePathState {
*
* It makes a looping path.
* It makes new unreachable segment, then it set the head with the segment.
*
* @param {string} label - A label of the continue statement.
* @param {string} label A label of the continue statement.
* @returns {void}
*/
makeContinue(label) {
@@ -1395,7 +1356,6 @@ class CodePathState {
*
* It registers the head segment to a context of `return`.
* It makes new unreachable segment, then it set the head with the segment.
*
* @returns {void}
*/
makeReturn() {
@@ -1412,7 +1372,6 @@ class CodePathState {
*
* It registers the head segment to a context of `throw`.
* It makes new unreachable segment, then it set the head with the segment.
*
* @returns {void}
*/
makeThrow() {
+10 -11
View File
@@ -21,10 +21,11 @@ const IdGenerator = require("./id-generator");
*/
class CodePath {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} id - An identifier.
* @param {CodePath|null} upper - The code path of the upper function scope.
* @param {Function} onLooped - A callback function to notify looping.
* @param {string} id An identifier.
* @param {CodePath|null} upper The code path of the upper function scope.
* @param {Function} onLooped A callback function to notify looping.
*/
constructor(id, upper, onLooped) {
@@ -62,8 +63,7 @@ class CodePath {
/**
* Gets the state of a given code path.
*
* @param {CodePath} codePath - A code path to get.
* @param {CodePath} codePath A code path to get.
* @returns {CodePathState} The state of the code path.
*/
static getState(codePath) {
@@ -126,11 +126,10 @@ class CodePath {
*
* - `controller.skip()` - Skip the following segments in this branch.
* - `controller.break()` - Skip all following segments.
*
* @param {Object} [options] - Omittable.
* @param {CodePathSegment} [options.first] - The first segment to traverse.
* @param {CodePathSegment} [options.last] - The last segment to traverse.
* @param {Function} callback - A callback function.
* @param {Object} [options] Omittable.
* @param {CodePathSegment} [options.first] The first segment to traverse.
* @param {CodePathSegment} [options.last] The last segment to traverse.
* @param {Function} callback A callback function.
* @returns {void}
*/
traverseSegments(options, callback) {
@@ -171,7 +170,7 @@ class CodePath {
/**
* Checks a given previous segment has been visited.
* @param {CodePathSegment} prevSegment - A previous segment to check.
* @param {CodePathSegment} prevSegment A previous segment to check.
* @returns {boolean} `true` if the segment has been visited.
*/
function isVisited(prevSegment) {
+8 -12
View File
@@ -17,7 +17,7 @@ const debug = require("debug")("eslint:code-path");
/**
* Gets id of a given segment.
* @param {CodePathSegment} segment - A segment to get.
* @param {CodePathSegment} segment A segment to get.
* @returns {string} Id of the segment.
*/
/* istanbul ignore next */
@@ -39,18 +39,16 @@ module.exports = {
/**
* Dumps given objects.
*
* @param {...any} args - objects to dump.
* @param {...any} args objects to dump.
* @returns {void}
*/
dump: debug,
/**
* Dumps the current analyzing state.
*
* @param {ASTNode} node - A node to dump.
* @param {CodePathState} state - A state to dump.
* @param {boolean} leaving - A flag whether or not it's leaving
* @param {ASTNode} node A node to dump.
* @param {CodePathState} state A state to dump.
* @param {boolean} leaving A flag whether or not it's leaving
* @returns {void}
*/
dumpState: !debug.enabled ? debug : /* istanbul ignore next */ function(node, state, leaving) {
@@ -73,8 +71,7 @@ module.exports = {
/**
* Dumps a DOT code of a given code path.
* The DOT code can be visialized with Graphvis.
*
* @param {CodePath} codePath - A code path to dump.
* @param {CodePath} codePath A code path to dump.
* @returns {void}
* @see http://www.graphviz.org
* @see http://www.webgraphviz.com
@@ -139,9 +136,8 @@ module.exports = {
/**
* Makes a DOT code of a given code path.
* The DOT code can be visialized with Graphvis.
*
* @param {CodePath} codePath - A code path to make DOT.
* @param {Object} traceMap - Optional. A map to check whether or not segments had been done.
* @param {CodePath} codePath A code path to make DOT.
* @param {Object} traceMap Optional. A map to check whether or not segments had been done.
* @returns {string} A DOT code of the code path.
*/
makeDotArrows(codePath, traceMap) {
+23 -34
View File
@@ -22,8 +22,7 @@ const assert = require("assert"),
/**
* Gets whether or not a given segment is reachable.
*
* @param {CodePathSegment} segment - A segment to get.
* @param {CodePathSegment} segment A segment to get.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -36,11 +35,10 @@ function isReachable(segment) {
* When `context.segmentsList` is `[[a, b], [c, d], [e, f]]`, `begin` is `0`, and
* `end` is `-1`, this creates `[g, h]`. This `g` is from `a`, `c`, and `e`.
* This `h` is from `b`, `d`, and `f`.
*
* @param {ForkContext} context - An instance.
* @param {number} begin - The first index of the previous segments.
* @param {number} end - The last index of the previous segments.
* @param {Function} create - A factory function of new segments.
* @param {ForkContext} context An instance.
* @param {number} begin The first index of the previous segments.
* @param {number} end The last index of the previous segments.
* @param {Function} create A factory function of new segments.
* @returns {CodePathSegment[]} New segments.
*/
function makeSegments(context, begin, end, create) {
@@ -69,9 +67,8 @@ function makeSegments(context, begin, end, create) {
* control statement (such as `break`, `continue`) from the `finally` block, the
* destination's segments may be half of the source segments. In that case, this
* merges segments.
*
* @param {ForkContext} context - An instance.
* @param {CodePathSegment[]} segments - Segments to merge.
* @param {ForkContext} context An instance.
* @param {CodePathSegment[]} segments Segments to merge.
* @returns {CodePathSegment[]} The merged segments.
*/
function mergeExtraSegments(context, segments) {
@@ -100,10 +97,11 @@ function mergeExtraSegments(context, segments) {
*/
class ForkContext {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {IdGenerator} idGenerator - An identifier generator for segments.
* @param {ForkContext|null} upper - An upper fork context.
* @param {number} count - A number of parallel segments.
* @param {IdGenerator} idGenerator An identifier generator for segments.
* @param {ForkContext|null} upper An upper fork context.
* @param {number} count A number of parallel segments.
*/
constructor(idGenerator, upper, count) {
this.idGenerator = idGenerator;
@@ -142,9 +140,8 @@ class ForkContext {
/**
* Creates new segments from this context.
*
* @param {number} begin - The first index of previous segments.
* @param {number} end - The last index of previous segments.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
*/
makeNext(begin, end) {
@@ -154,9 +151,8 @@ class ForkContext {
/**
* Creates new segments from this context.
* The new segments is always unreachable.
*
* @param {number} begin - The first index of previous segments.
* @param {number} end - The last index of previous segments.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
*/
makeUnreachable(begin, end) {
@@ -167,9 +163,8 @@ class ForkContext {
* Creates new segments from this context.
* The new segments don't have connections for previous segments.
* But these inherit the reachable flag from this context.
*
* @param {number} begin - The first index of previous segments.
* @param {number} end - The last index of previous segments.
* @param {number} begin The first index of previous segments.
* @param {number} end The last index of previous segments.
* @returns {CodePathSegment[]} New segments.
*/
makeDisconnected(begin, end) {
@@ -179,8 +174,7 @@ class ForkContext {
/**
* Adds segments into this context.
* The added segments become the head.
*
* @param {CodePathSegment[]} segments - Segments to add.
* @param {CodePathSegment[]} segments Segments to add.
* @returns {void}
*/
add(segments) {
@@ -192,8 +186,7 @@ class ForkContext {
/**
* Replaces the head segments with given segments.
* The current head segments are removed.
*
* @param {CodePathSegment[]} segments - Segments to add.
* @param {CodePathSegment[]} segments Segments to add.
* @returns {void}
*/
replaceHead(segments) {
@@ -204,8 +197,7 @@ class ForkContext {
/**
* Adds all segments of a given fork context into this context.
*
* @param {ForkContext} context - A fork context to add.
* @param {ForkContext} context A fork context to add.
* @returns {void}
*/
addAll(context) {
@@ -220,7 +212,6 @@ class ForkContext {
/**
* Clears all secments in this context.
*
* @returns {void}
*/
clear() {
@@ -229,8 +220,7 @@ class ForkContext {
/**
* Creates the root fork context.
*
* @param {IdGenerator} idGenerator - An identifier generator for segments.
* @param {IdGenerator} idGenerator An identifier generator for segments.
* @returns {ForkContext} New fork context.
*/
static newRoot(idGenerator) {
@@ -243,9 +233,8 @@ class ForkContext {
/**
* Creates an empty fork context preceded by a given context.
*
* @param {ForkContext} parentContext - The parent fork context.
* @param {boolean} forkLeavingPath - A flag which shows inside of `finally` block.
* @param {ForkContext} parentContext The parent fork context.
* @param {boolean} forkLeavingPath A flag which shows inside of `finally` block.
* @returns {ForkContext} New fork context.
*/
static newEmpty(parentContext, forkLeavingPath) {
+2 -2
View File
@@ -18,8 +18,9 @@
*/
class IdGenerator {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {string} prefix - Optional. A prefix of generated ids.
* @param {string} prefix Optional. A prefix of generated ids.
*/
constructor(prefix) {
this.prefix = String(prefix);
@@ -28,7 +29,6 @@ class IdGenerator {
/**
* Generates id.
*
* @returns {string} A generated id.
*/
next() {
+133 -107
View File
@@ -292,10 +292,15 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
if (!match) {
return;
}
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(match[1]);
const directiveText = match[1];
const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(directiveText);
if (warnInlineConfig && (lineCommentSupported || comment.type === "Block")) {
const kind = comment.type === "Block" ? `/*${match[1]}*/` : `//${match[1]}`;
if (comment.type === "Line" && !lineCommentSupported) {
return;
}
if (warnInlineConfig) {
const kind = comment.type === "Block" ? `/*${directiveText}*/` : `//${directiveText}`;
problems.push(createLintingProblem({
ruleId: null,
@@ -306,108 +311,101 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
return;
}
const directiveValue = trimmedCommentText.slice(match.index + match[1].length);
let directiveType = "";
if (lineCommentSupported && comment.loc.start.line !== comment.loc.end.line) {
const message = `${directiveText} comment should not span multiple lines.`;
if (lineCommentSupported) {
if (comment.loc.start.line === comment.loc.end.line) {
directiveType = match[1].slice("eslint-".length);
} else {
const message = `${match[1]} comment should not span multiple lines.`;
problems.push(createLintingProblem({
ruleId: null,
message,
loc: comment.loc
}));
}
} else if (comment.type === "Block") {
switch (match[1]) {
case "exported":
Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
case "globals":
case "global":
for (const [id, { value }] of Object.entries(commentParser.parseStringConfig(directiveValue, comment))) {
let normalizedValue;
try {
normalizedValue = ConfigOps.normalizeConfigGlobal(value);
} catch (err) {
problems.push(createLintingProblem({
ruleId: null,
loc: comment.loc,
message: err.message
}));
continue;
}
if (enabledGlobals[id]) {
enabledGlobals[id].comments.push(comment);
enabledGlobals[id].value = normalizedValue;
} else {
enabledGlobals[id] = {
comments: [comment],
value: normalizedValue
};
}
}
break;
case "eslint-disable":
directiveType = "disable";
break;
case "eslint-enable":
directiveType = "enable";
break;
case "eslint": {
const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
if (parseResult.success) {
Object.keys(parseResult.config).forEach(name => {
const rule = ruleMapper(name);
const ruleValue = parseResult.config[name];
if (rule === null) {
problems.push(createLintingProblem({ ruleId: name, loc: comment.loc }));
return;
}
try {
validator.validateRuleOptions(rule, name, ruleValue);
} catch (err) {
problems.push(createLintingProblem({
ruleId: name,
message: err.message,
loc: comment.loc
}));
// do not apply the config, if found invalid options.
return;
}
configuredRules[name] = ruleValue;
});
} else {
problems.push(parseResult.error);
}
break;
}
// no default
}
problems.push(createLintingProblem({
ruleId: null,
message,
loc: comment.loc
}));
return;
}
if (directiveType !== "") {
const options = { type: directiveType, loc: comment.loc, value: directiveValue, ruleMapper };
const { directives, directiveProblems } = createDisableDirectives(options);
const directiveValue = trimmedCommentText.slice(match.index + directiveText.length);
disableDirectives.push(...directives);
problems.push(...directiveProblems);
switch (directiveText) {
case "eslint-disable":
case "eslint-enable":
case "eslint-disable-next-line":
case "eslint-disable-line": {
const directiveType = directiveText.slice("eslint-".length);
const options = { type: directiveType, loc: comment.loc, value: directiveValue, ruleMapper };
const { directives, directiveProblems } = createDisableDirectives(options);
disableDirectives.push(...directives);
problems.push(...directiveProblems);
break;
}
case "exported":
Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
case "globals":
case "global":
for (const [id, { value }] of Object.entries(commentParser.parseStringConfig(directiveValue, comment))) {
let normalizedValue;
try {
normalizedValue = ConfigOps.normalizeConfigGlobal(value);
} catch (err) {
problems.push(createLintingProblem({
ruleId: null,
loc: comment.loc,
message: err.message
}));
continue;
}
if (enabledGlobals[id]) {
enabledGlobals[id].comments.push(comment);
enabledGlobals[id].value = normalizedValue;
} else {
enabledGlobals[id] = {
comments: [comment],
value: normalizedValue
};
}
}
break;
case "eslint": {
const parseResult = commentParser.parseJsonConfig(directiveValue, comment.loc);
if (parseResult.success) {
Object.keys(parseResult.config).forEach(name => {
const rule = ruleMapper(name);
const ruleValue = parseResult.config[name];
if (rule === null) {
problems.push(createLintingProblem({ ruleId: name, loc: comment.loc }));
return;
}
try {
validator.validateRuleOptions(rule, name, ruleValue);
} catch (err) {
problems.push(createLintingProblem({
ruleId: name,
message: err.message,
loc: comment.loc
}));
// do not apply the config, if found invalid options.
return;
}
configuredRules[name] = ruleValue;
});
} else {
problems.push(parseResult.error);
}
break;
}
// no default
}
});
@@ -438,7 +436,7 @@ const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//gu;
/**
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
* @param {string} text - A source code text to check.
* @param {string} text A source code text to check.
* @returns {Object|null} A result of parseListConfig() with "eslint-env *" comment.
*/
function findEslintEnv(text) {
@@ -555,8 +553,7 @@ function resolveGlobals(providedGlobals, enabledEnvironments) {
/**
* Strips Unicode BOM from a given text.
*
* @param {string} text - A text to strip.
* @param {string} text A text to strip.
* @returns {string} The stripped text.
*/
function stripUnicodeBOM(text) {
@@ -669,6 +666,8 @@ function parse(text, parser, providedParserOptions, filePath) {
// If the message includes a leading line number, strip it:
const message = `Parsing error: ${ex.message.replace(/^line \d+:/iu, "").trim()}`;
debug("%s\n%s", message, ex.stack);
return {
success: false,
error: {
@@ -813,9 +812,10 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
* @param {Object} settings The settings that were enabled in the config
* @param {string} filename The reported filename of the code
* @param {boolean} disableFixes If true, it doesn't make `fix` properties.
* @param {string | undefined} cwd cwd of the cli
* @returns {Problem[]} An array of reported problems
*/
function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parserName, settings, filename, disableFixes) {
function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parserName, settings, filename, disableFixes, cwd) {
const emitter = createEmitter();
const nodeQueue = [];
let currentNode = sourceCode.ast;
@@ -842,6 +842,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
{
getAncestors: () => getAncestors(currentNode),
getDeclaredVariables: sourceCode.scopeManager.getDeclaredVariables.bind(sourceCode.scopeManager),
getCwd: () => cwd,
getFilename: () => filename,
getScope: () => getScope(sourceCode.scopeManager, currentNode),
getSourceCode: () => sourceCode,
@@ -988,6 +989,24 @@ function getRule(slots, ruleId) {
);
}
/**
* Normalize the value of the cwd
* @param {string | undefined} cwd raw value of the cwd, path to a directory that should be considered as the current working directory, can be undefined.
* @returns {string | undefined} normalized cwd
*/
function normalizeCwd(cwd) {
if (cwd) {
return cwd;
}
if (typeof process === "object") {
return process.cwd();
}
// It's more explicit to assign the undefined
// eslint-disable-next-line no-undefined
return undefined;
}
/**
* The map to store private data.
* @type {WeakMap<Linter, LinterInternalSlots>}
@@ -1004,8 +1023,14 @@ const internalSlotsMap = new WeakMap();
*/
class Linter {
constructor() {
/**
* Initialize the Linter.
* @param {Object} [config] the config object
* @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
*/
constructor({ cwd } = {}) {
internalSlotsMap.set(this, {
cwd: normalizeCwd(cwd),
lastConfigArray: null,
lastSourceCode: null,
parserMap: new Map([["espree", espree]]),
@@ -1137,7 +1162,8 @@ class Linter {
parserName,
settings,
options.filename,
options.disableFixes
options.disableFixes,
slots.cwd
);
} catch (err) {
err.message += `\nOccurred while linting ${options.filename}`;
+3 -2
View File
@@ -202,6 +202,7 @@ const parseSelector = lodash.memoize(rawSelector => {
*/
class NodeEventGenerator {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {SafeEmitter} emitter
* An SafeEmitter which is the destination of events. This emitter must already
@@ -286,7 +287,7 @@ class NodeEventGenerator {
/**
* Emits an event of entering AST node.
* @param {ASTNode} node - A node which was entered.
* @param {ASTNode} node A node which was entered.
* @returns {void}
*/
enterNode(node) {
@@ -298,7 +299,7 @@ class NodeEventGenerator {
/**
* Emits an event of leaving AST node.
* @param {ASTNode} node - A node which was left.
* @param {ASTNode} node A node which was left.
* @returns {void}
*/
leaveNode(node) {
+6 -8
View File
@@ -78,8 +78,7 @@ const hasOwnProperty = Function.call.bind(Object.hasOwnProperty);
/**
* Clones a given value deeply.
* Note: This ignores `parent` property.
*
* @param {any} x - A value to clone.
* @param {any} x A value to clone.
* @returns {any} A cloned value.
*/
function cloneDeeplyExcludesParent(x) {
@@ -104,8 +103,7 @@ function cloneDeeplyExcludesParent(x) {
/**
* Freezes a given value deeply.
*
* @param {any} x - A value to freeze.
* @param {any} x A value to freeze.
* @returns {void}
*/
function freezeDeeply(x) {
@@ -146,8 +144,8 @@ const IT = Symbol("it");
/**
* This is `it` default handler if `it` don't exist.
* @this {Mocha}
* @param {string} text - The description of the test case.
* @param {Function} method - The logic of the test case.
* @param {string} text The description of the test case.
* @param {Function} method The logic of the test case.
* @returns {any} Returned value of `method`.
*/
function itDefaultHandler(text, method) {
@@ -164,8 +162,8 @@ function itDefaultHandler(text, method) {
/**
* This is `describe` default handler if `describe` don't exist.
* @this {Mocha}
* @param {string} text - The description of the test case.
* @param {Function} method - The logic of the test case.
* @param {string} text The description of the test case.
* @param {Function} method The logic of the test case.
* @returns {any} Returned value of `method`.
*/
function describeDefaultHandler(text, method) {
+8 -8
View File
@@ -79,7 +79,7 @@ function areEqualKeys(left, right) {
/**
* Checks whether or not a given node is of an accessor kind ('get' or 'set').
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is of an accessor kind.
*/
function isAccessorKind(node) {
@@ -88,8 +88,8 @@ function isAccessorKind(node) {
/**
* Checks whether or not a given node is an `Identifier` node which was named a given name.
* @param {ASTNode} node - A node to check.
* @param {string} name - An expected name of the node.
* @param {ASTNode} node A node to check.
* @param {string} name An expected name of the node.
* @returns {boolean} `true` if the node is an `Identifier` node which was named as expected.
*/
function isIdentifier(node, name) {
@@ -98,10 +98,10 @@ function isIdentifier(node, name) {
/**
* Checks whether or not a given node is an argument of a specified method call.
* @param {ASTNode} node - A node to check.
* @param {number} index - An expected index of the node in arguments.
* @param {string} object - An expected name of the object of the method.
* @param {string} property - An expected name of the method.
* @param {ASTNode} node A node to check.
* @param {number} index An expected index of the node in arguments.
* @param {string} object An expected name of the object of the method.
* @param {string} property An expected name of the method.
* @returns {boolean} `true` if the node is an argument of the specified method call.
*/
function isArgumentOfMethodCall(node, index, object, property) {
@@ -119,7 +119,7 @@ function isArgumentOfMethodCall(node, index, object, property) {
/**
* Checks whether or not a given node is a property descriptor.
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is a property descriptor.
*/
function isPropertyDescriptor(node) {
+12 -15
View File
@@ -65,8 +65,7 @@ module.exports = {
/**
* Normalizes a given option value.
*
* @param {string|Object|undefined} option - An option value to parse.
* @param {string|Object|undefined} option An option value to parse.
* @returns {{multiline: boolean, minItems: number}} Normalized option object.
*/
function normalizeOptionValue(option) {
@@ -97,8 +96,7 @@ module.exports = {
/**
* Normalizes a given option value.
*
* @param {string|Object|undefined} options - An option value to parse.
* @param {string|Object|undefined} options An option value to parse.
* @returns {{ArrayExpression: {multiline: boolean, minItems: number}, ArrayPattern: {multiline: boolean, minItems: number}}} Normalized option object.
*/
function normalizeOptions(options) {
@@ -109,8 +107,8 @@ module.exports = {
/**
* Reports that there shouldn't be a linebreak after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportNoBeginningLinebreak(node, token) {
@@ -132,8 +130,8 @@ module.exports = {
/**
* Reports that there shouldn't be a linebreak before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportNoEndingLinebreak(node, token) {
@@ -155,8 +153,8 @@ module.exports = {
/**
* Reports that there should be a linebreak after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredBeginningLinebreak(node, token) {
@@ -172,8 +170,8 @@ module.exports = {
/**
* Reports that there should be a linebreak before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredEndingLinebreak(node, token) {
@@ -189,8 +187,7 @@ module.exports = {
/**
* Reports a given node if it violated this rule.
*
* @param {ASTNode} node - A node to check. This is an ArrayExpression node or an ArrayPattern node.
* @param {ASTNode} node A node to check. This is an ArrayExpression node or an ArrayPattern node.
* @returns {void}
*/
function check(node) {
@@ -219,7 +216,7 @@ module.exports = {
) ||
(
options.consistent &&
firstIncComment.loc.start.line !== openBracket.loc.end.line
openBracket.loc.end.line !== first.loc.start.line
)
);
+12 -12
View File
@@ -59,7 +59,7 @@ module.exports = {
* Determines whether an option is set, relative to the spacing option.
* If spaced is "always", then check whether option is set to false.
* If spaced is "never", then check whether option is set to true.
* @param {Object} option - The option to exclude.
* @param {Object} option The option to exclude.
* @returns {boolean} Whether or not the property is excluded.
*/
function isOptionSet(option) {
@@ -79,8 +79,8 @@ module.exports = {
/**
* Reports that there shouldn't be a space after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportNoBeginningSpace(node, token) {
@@ -101,8 +101,8 @@ module.exports = {
/**
* Reports that there shouldn't be a space before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportNoEndingSpace(node, token) {
@@ -123,8 +123,8 @@ module.exports = {
/**
* Reports that there should be a space after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredBeginningSpace(node, token) {
@@ -143,8 +143,8 @@ module.exports = {
/**
* Reports that there should be a space before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredEndingSpace(node, token) {
@@ -163,7 +163,7 @@ module.exports = {
/**
* Determines if a node is an object type
* @param {ASTNode} node - The node to check.
* @param {ASTNode} node The node to check.
* @returns {boolean} Whether or not the node is an object type.
*/
function isObjectType(node) {
@@ -172,7 +172,7 @@ module.exports = {
/**
* Determines if a node is an array type
* @param {ASTNode} node - The node to check.
* @param {ASTNode} node The node to check.
* @returns {boolean} Whether or not the node is an array type.
*/
function isArrayType(node) {
@@ -181,7 +181,7 @@ module.exports = {
/**
* Validates the spacing around array brackets
* @param {ASTNode} node - The node we're checking for spacing
* @param {ASTNode} node The node we're checking for spacing
* @returns {void}
*/
function validateArraySpacing(node) {
+6 -11
View File
@@ -22,8 +22,7 @@ const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|som
/**
* Checks a given code path segment is reachable.
*
* @param {CodePathSegment} segment - A segment to check.
* @param {CodePathSegment} segment A segment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -35,9 +34,8 @@ function isReachable(segment) {
*
* - FunctionExpression -> the function name or `function` keyword.
* - ArrowFunctionExpression -> `=>` token.
*
* @param {ASTNode} node - A function node to get.
* @param {SourceCode} sourceCode - A source code to get tokens.
* @param {ASTNode} node A function node to get.
* @param {SourceCode} sourceCode A source code to get tokens.
* @returns {ASTNode|Token} The node or the token of a location.
*/
function getLocation(node, sourceCode) {
@@ -50,8 +48,7 @@ function getLocation(node, sourceCode) {
/**
* Checks a given node is a MemberExpression node which has the specified name's
* property.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is a MemberExpression node which has
* the specified name's property
*/
@@ -65,8 +62,7 @@ function isTargetMethod(node) {
/**
* Checks whether or not a given node is a function expression which is the
* callback of an array method.
*
* @param {ASTNode} node - A node to check. This is one of
* @param {ASTNode} node A node to check. This is one of
* FunctionExpression or ArrowFunctionExpression.
* @returns {boolean} `true` if the node is the callback of an array method.
*/
@@ -188,8 +184,7 @@ module.exports = {
*
* If the last code path segment is reachable, there are paths which are not
* returned or thrown.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {void}
*/
function checkLastSegment(node) {
+5 -8
View File
@@ -62,8 +62,7 @@ module.exports = {
/**
* Normalizes a given option value.
*
* @param {string|Object|undefined} providedOption - An option value to parse.
* @param {string|Object|undefined} providedOption An option value to parse.
* @returns {{multiline: boolean, minItems: number}} Normalized option object.
*/
function normalizeOptionValue(providedOption) {
@@ -90,8 +89,7 @@ module.exports = {
/**
* Normalizes a given option value.
*
* @param {string|Object|undefined} options - An option value to parse.
* @param {string|Object|undefined} options An option value to parse.
* @returns {{ArrayExpression: {multiline: boolean, minItems: number}, ArrayPattern: {multiline: boolean, minItems: number}}} Normalized option object.
*/
function normalizeOptions(options) {
@@ -102,7 +100,7 @@ module.exports = {
/**
* Reports that there shouldn't be a line break after the first token
* @param {Token} token - The token to use for the report.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportNoLineBreak(token) {
@@ -151,7 +149,7 @@ module.exports = {
/**
* Reports that there should be a line break after the first token
* @param {Token} token - The token to use for the report.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredLineBreak(token) {
@@ -171,8 +169,7 @@ module.exports = {
/**
* Reports a given node if it violated this rule.
*
* @param {ASTNode} node - A node to check. This is an ObjectExpression node or an ObjectPattern node.
* @param {ASTNode} node A node to check. This is an ObjectExpression node or an ObjectPattern node.
* @returns {void}
*/
function check(node) {
-1
View File
@@ -16,7 +16,6 @@ const astUtils = require("./utils/ast-utils");
/**
* Get location should be reported by AST node.
*
* @param {ASTNode} node AST Node.
* @returns {Location} Location information.
*/
+3 -3
View File
@@ -31,7 +31,7 @@ module.exports = {
/**
* Makes a block scope.
* @param {ASTNode} node - A node of a scope.
* @param {ASTNode} node A node of a scope.
* @returns {void}
*/
function enterScope(node) {
@@ -48,7 +48,7 @@ module.exports = {
/**
* Reports a given reference.
* @param {eslint-scope.Reference} reference - A reference to report.
* @param {eslint-scope.Reference} reference A reference to report.
* @returns {void}
*/
function report(reference) {
@@ -59,7 +59,7 @@ module.exports = {
/**
* Finds and reports references which are outside of valid scopes.
* @param {ASTNode} node - A node to get variables.
* @param {ASTNode} node A node to get variables.
* @returns {void}
*/
function checkForVariables(node) {
+4 -4
View File
@@ -41,7 +41,7 @@ module.exports = {
/**
* Gets the open brace token from a given node.
* @param {ASTNode} node - A BlockStatement/SwitchStatement node to get.
* @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
* @returns {Token} The token of the open brace.
*/
function getOpenBrace(node) {
@@ -58,8 +58,8 @@ module.exports = {
* Checks whether or not:
* - given tokens are on same line.
* - there is/isn't a space between given tokens.
* @param {Token} left - A token to check.
* @param {Token} right - The token which is next to `left`.
* @param {Token} left A token to check.
* @param {Token} right The token which is next to `left`.
* @returns {boolean}
* When the option is `"always"`, `true` if there are one or more spaces between given tokens.
* When the option is `"never"`, `true` if there are not any spaces between given tokens.
@@ -74,7 +74,7 @@ module.exports = {
/**
* Reports invalid spacing style inside braces.
* @param {ASTNode} node - A BlockStatement/SwitchStatement node to get.
* @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
* @returns {void}
*/
function checkSpacingInsideBraces(node) {
-7
View File
@@ -54,7 +54,6 @@ const DEFAULTS = {
* set is returned. Options specified in overrides will take priority
* over options specified in the main options object, which will in
* turn take priority over the rule's defaults.
*
* @param {Object|string} rawOptions The user-provided options.
* @param {string} which Either "line" or "block".
* @returns {Object} The normalized options.
@@ -65,7 +64,6 @@ function getNormalizedOptions(rawOptions, which) {
/**
* Get normalized options for block and line comments.
*
* @param {Object|string} rawOptions The user-provided options.
* @returns {Object} An object with "Line" and "Block" keys and corresponding
* normalized options objects.
@@ -82,7 +80,6 @@ function getAllNormalizedOptions(rawOptions = {}) {
* options.
*
* This is done in order to avoid invoking the RegExp constructor repeatedly.
*
* @param {Object} normalizedOptions The normalized rule options.
* @returns {void}
*/
@@ -162,7 +159,6 @@ module.exports = {
* Also, it follows from this definition that only block comments can
* be considered as possibly inline. This is because line comments
* would consume any following tokens on the same line as the comment.
*
* @param {ASTNode} comment The comment node to check.
* @returns {boolean} True if the comment is an inline comment, false
* otherwise.
@@ -181,7 +177,6 @@ module.exports = {
/**
* Determine if a comment follows another comment.
*
* @param {ASTNode} comment The comment to check.
* @returns {boolean} True if the comment follows a valid comment.
*/
@@ -196,7 +191,6 @@ module.exports = {
/**
* Check a comment to determine if it is valid for this rule.
*
* @param {ASTNode} comment The comment node to process.
* @param {Object} options The options for checking this comment.
* @returns {boolean} True if the comment is valid, false otherwise.
@@ -261,7 +255,6 @@ module.exports = {
/**
* Process a comment to determine if it needs to be reported.
*
* @param {ASTNode} comment The comment node to process.
* @returns {void}
*/
+3 -3
View File
@@ -61,7 +61,7 @@ module.exports = {
/**
* Check if the node is an instance method
* @param {ASTNode} node - node to check
* @param {ASTNode} node node to check
* @returns {boolean} True if its an instance method
* @private
*/
@@ -71,7 +71,7 @@ module.exports = {
/**
* Check if the node is an instance method not excluded by config
* @param {ASTNode} node - node to check
* @param {ASTNode} node node to check
* @returns {boolean} True if it is an instance method, and not excluded by config
* @private
*/
@@ -84,7 +84,7 @@ module.exports = {
* Checks if we are leaving a function that is a method, and reports if 'this' has not been used.
* Static methods and the constructor are exempt.
* Then pops the context off the stack.
* @param {ASTNode} node - A function node that was entered.
* @param {ASTNode} node A function node that was entered.
* @returns {void}
* @private
*/
+15 -23
View File
@@ -27,8 +27,7 @@ const DEFAULT_OPTIONS = Object.freeze({
/**
* Checks whether or not a trailing comma is allowed in a given node.
* If the `lastItem` is `RestElement` or `RestProperty`, it disallows trailing commas.
*
* @param {ASTNode} lastItem - The node of the last element in the given node.
* @param {ASTNode} lastItem The node of the last element in the given node.
* @returns {boolean} `true` if a trailing comma is allowed.
*/
function isTrailingCommaAllowed(lastItem) {
@@ -41,20 +40,18 @@ function isTrailingCommaAllowed(lastItem) {
/**
* Normalize option value.
*
* @param {string|Object|undefined} optionValue - The 1st option value to normalize.
* @param {string|Object|undefined} optionValue The 1st option value to normalize.
* @param {number} ecmaVersion The normalized ECMAScript version.
* @returns {Object} The normalized option value.
*/
function normalizeOptions(optionValue) {
function normalizeOptions(optionValue, ecmaVersion) {
if (typeof optionValue === "string") {
return {
arrays: optionValue,
objects: optionValue,
imports: optionValue,
exports: optionValue,
// For backward compatibility, always ignore functions.
functions: "ignore"
functions: (!ecmaVersion || ecmaVersion < 8) ? "ignore" : optionValue
};
}
if (typeof optionValue === "object" && optionValue !== null) {
@@ -137,12 +134,13 @@ module.exports = {
},
create(context) {
const options = normalizeOptions(context.options[0]);
const options = normalizeOptions(context.options[0], context.parserOptions.ecmaVersion);
const sourceCode = context.getSourceCode();
/**
* Gets the last item of the given node.
* @param {ASTNode} node - The node to get.
* @param {ASTNode} node The node to get.
* @returns {ASTNode|null} The last node or null.
*/
function getLastItem(node) {
@@ -172,9 +170,8 @@ module.exports = {
* Gets the trailing comma token of the given node.
* If the trailing comma does not exist, this returns the token which is
* the insertion point of the trailing comma token.
*
* @param {ASTNode} node - The node to get.
* @param {ASTNode} lastItem - The last item of the node.
* @param {ASTNode} node The node to get.
* @param {ASTNode} lastItem The last item of the node.
* @returns {Token} The trailing comma token or the insertion point.
*/
function getTrailingToken(node, lastItem) {
@@ -199,8 +196,7 @@ module.exports = {
* Checks whether or not a given node is multiline.
* This rule handles a given node as multiline when the closing parenthesis
* and the last element are not on the same line.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is multiline.
*/
function isMultiline(node) {
@@ -218,8 +214,7 @@ module.exports = {
/**
* Reports a trailing comma if it exists.
*
* @param {ASTNode} node - A node to check. Its type is one of
* @param {ASTNode} node A node to check. Its type is one of
* ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
* ImportDeclaration, and ExportNamedDeclaration.
* @returns {void}
@@ -251,8 +246,7 @@ module.exports = {
*
* If a given node is `ArrayPattern` which has `RestElement`, the trailing
* comma is disallowed, so report if it exists.
*
* @param {ASTNode} node - A node to check. Its type is one of
* @param {ASTNode} node A node to check. Its type is one of
* ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
* ImportDeclaration, and ExportNamedDeclaration.
* @returns {void}
@@ -286,8 +280,7 @@ module.exports = {
* If a given node is multiline, reports the last element of a given node
* when it does not have a trailing comma.
* Otherwise, reports a trailing comma if it exists.
*
* @param {ASTNode} node - A node to check. Its type is one of
* @param {ASTNode} node A node to check. Its type is one of
* ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
* ImportDeclaration, and ExportNamedDeclaration.
* @returns {void}
@@ -304,8 +297,7 @@ module.exports = {
* Only if a given node is not multiline, reports the last element of a given node
* when it does not have a trailing comma.
* Otherwise, reports a trailing comma if it exists.
*
* @param {ASTNode} node - A node to check. Its type is one of
* @param {ASTNode} node A node to check. Its type is one of
* ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
* ImportDeclaration, and ExportNamedDeclaration.
* @returns {void}
+1 -1
View File
@@ -105,7 +105,7 @@ module.exports = {
/**
* Validates the spacing around a comma token.
* @param {Object} tokens - The tokens to be validated.
* @param {Object} tokens The tokens to be validated.
* @param {Token} tokens.comma The token representing the comma.
* @param {Token} [tokens.left] The last token before the comma.
* @param {Token} [tokens.right] The first token after the comma.
+10 -10
View File
@@ -59,9 +59,9 @@ module.exports = {
/**
* Reports that there shouldn't be a space after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {Token} tokenAfter - The token after `token`.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @param {Token} tokenAfter The token after `token`.
* @returns {void}
*/
function reportNoBeginningSpace(node, token, tokenAfter) {
@@ -80,9 +80,9 @@ module.exports = {
/**
* Reports that there shouldn't be a space before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {Token} tokenBefore - The token before `token`.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @param {Token} tokenBefore The token before `token`.
* @returns {void}
*/
function reportNoEndingSpace(node, token, tokenBefore) {
@@ -101,8 +101,8 @@ module.exports = {
/**
* Reports that there should be a space after the first token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredBeginningSpace(node, token) {
@@ -121,8 +121,8 @@ module.exports = {
/**
* Reports that there should be a space before the last token
* @param {ASTNode} node - The node to report in the event of an error.
* @param {Token} token - The token to use for the report.
* @param {ASTNode} node The node to report in the event of an error.
* @param {Token} token The token to use for the report.
* @returns {void}
*/
function reportRequiredEndingSpace(node, token) {
+4 -5
View File
@@ -18,8 +18,8 @@ const astUtils = require("./utils/ast-utils");
/**
* Checks whether or not a given node is an `Identifier` node which was named a given name.
* @param {ASTNode} node - A node to check.
* @param {string} name - An expected name of the node.
* @param {ASTNode} node A node to check.
* @param {string} name An expected name of the node.
* @returns {boolean} `true` if the node is an `Identifier` node which was named as expected.
*/
function isIdentifier(node, name) {
@@ -28,7 +28,7 @@ function isIdentifier(node, name) {
/**
* Checks whether or not a given code path segment is unreachable.
* @param {CodePathSegment} segment - A CodePathSegment to check.
* @param {CodePathSegment} segment A CodePathSegment to check.
* @returns {boolean} `true` if the segment is unreachable.
*/
function isUnreachable(segment) {
@@ -88,8 +88,7 @@ module.exports = {
/**
* Checks whether of not the implicit returning is consistent if the last
* code path segment is reachable.
*
* @param {ASTNode} node - A program/function node to check.
* @param {ASTNode} node A program/function node to check.
* @returns {void}
*/
function checkLastSegment(node) {
+5 -5
View File
@@ -46,8 +46,8 @@ module.exports = {
/**
* Reports that a variable declarator or assignment expression is assigning
* a non-'this' value to the specified alias.
* @param {ASTNode} node - The assigning node.
* @param {string} name - the name of the alias that was incorrectly used.
* @param {ASTNode} node The assigning node.
* @param {string} name the name of the alias that was incorrectly used.
* @returns {void}
*/
function reportBadAssignment(node, name) {
@@ -57,9 +57,9 @@ module.exports = {
/**
* Checks that an assignment to an identifier only assigns 'this' to the
* appropriate alias, and the alias is only assigned to 'this'.
* @param {ASTNode} node - The assigning node.
* @param {Identifier} name - The name of the variable assigned to.
* @param {Expression} value - The value of the assignment.
* @param {ASTNode} node The assigning node.
* @param {Identifier} name The name of the variable assigned to.
* @param {Expression} value The value of the assignment.
* @returns {void}
*/
function checkAssignment(node, name, value) {
+14 -16
View File
@@ -11,8 +11,7 @@
/**
* Checks whether a given code path segment is reachable or not.
*
* @param {CodePathSegment} segment - A code path segment to check.
* @param {CodePathSegment} segment A code path segment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -21,7 +20,7 @@ function isReachable(segment) {
/**
* Checks whether or not a given node is a constructor.
* @param {ASTNode} node - A node to check. This node type is one of
* @param {ASTNode} node A node to check. This node type is one of
* `Program`, `FunctionDeclaration`, `FunctionExpression`, and
* `ArrowFunctionExpression`.
* @returns {boolean} `true` if the node is a constructor.
@@ -36,8 +35,7 @@ function isConstructorFunction(node) {
/**
* Checks whether a given node can be a constructor or not.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node can be a constructor.
*/
function isPossibleConstructor(node) {
@@ -137,7 +135,7 @@ module.exports = {
/**
* Gets the flag which shows `super()` is called in some paths.
* @param {CodePathSegment} segment - A code path segment to get.
* @param {CodePathSegment} segment A code path segment to get.
* @returns {boolean} The flag which shows `super()` is called in some paths
*/
function isCalledInSomePath(segment) {
@@ -146,7 +144,7 @@ module.exports = {
/**
* Gets the flag which shows `super()` is called in all paths.
* @param {CodePathSegment} segment - A code path segment to get.
* @param {CodePathSegment} segment A code path segment to get.
* @returns {boolean} The flag which shows `super()` is called in all paths.
*/
function isCalledInEveryPath(segment) {
@@ -168,8 +166,8 @@ module.exports = {
/**
* Stacks a constructor information.
* @param {CodePath} codePath - A code path which was started.
* @param {ASTNode} node - The current node.
* @param {CodePath} codePath A code path which was started.
* @param {ASTNode} node The current node.
* @returns {void}
*/
onCodePathStart(codePath, node) {
@@ -200,8 +198,8 @@ module.exports = {
/**
* Pops a constructor information.
* And reports if `super()` lacked.
* @param {CodePath} codePath - A code path which was ended.
* @param {ASTNode} node - The current node.
* @param {CodePath} codePath A code path which was ended.
* @param {ASTNode} node The current node.
* @returns {void}
*/
onCodePathEnd(codePath, node) {
@@ -231,7 +229,7 @@ module.exports = {
/**
* Initialize information of a given code path segment.
* @param {CodePathSegment} segment - A code path segment to initialize.
* @param {CodePathSegment} segment A code path segment to initialize.
* @returns {void}
*/
onCodePathSegmentStart(segment) {
@@ -258,9 +256,9 @@ module.exports = {
/**
* Update information of the code path segment when a code path was
* looped.
* @param {CodePathSegment} fromSegment - The code path segment of the
* @param {CodePathSegment} fromSegment The code path segment of the
* end of a loop.
* @param {CodePathSegment} toSegment - A code path segment of the head
* @param {CodePathSegment} toSegment A code path segment of the head
* of a loop.
* @returns {void}
*/
@@ -303,7 +301,7 @@ module.exports = {
/**
* Checks for a call of `super()`.
* @param {ASTNode} node - A CallExpression node to check.
* @param {ASTNode} node A CallExpression node to check.
* @returns {void}
*/
"CallExpression:exit"(node) {
@@ -358,7 +356,7 @@ module.exports = {
/**
* Set the mark to the returned path as `super()` was called.
* @param {ASTNode} node - A ReturnStatement node to check.
* @param {ASTNode} node A ReturnStatement node to check.
* @returns {void}
*/
ReturnStatement(node) {
+3 -5
View File
@@ -119,8 +119,7 @@ module.exports = {
/**
* Checks if the given token is an `else` token or not.
*
* @param {Token} token - The token to check.
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is an `else` token.
*/
function isElseKeywordToken(token) {
@@ -129,7 +128,7 @@ module.exports = {
/**
* Gets the `else` keyword token of a given `IfStatement` node.
* @param {ASTNode} node - A `IfStatement` node to get.
* @param {ASTNode} node A `IfStatement` node to get.
* @returns {Token} The `else` keyword token.
*/
function getElseKeyword(node) {
@@ -143,8 +142,7 @@ module.exports = {
* 1. The given node has the `alternate` node.
* 2. There is a `IfStatement` which doesn't have `alternate` node in the
* trailing statement chain of the `consequent` node.
*
* @param {ASTNode} node - A IfStatement node to check.
* @param {ASTNode} node A IfStatement node to check.
* @returns {boolean} `true` if the node requires braces of the consequent chunk.
*/
function requiresBraceOfConsequent(node) {
+1
View File
@@ -25,6 +25,7 @@ module.exports = {
create(context) {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {ASTNode} node function node
* @returns {void}
+11 -12
View File
@@ -47,19 +47,18 @@ module.exports = {
/**
* Reports if the dot between object and property is on the correct loccation.
* @param {ASTNode} obj The object owning the property.
* @param {ASTNode} prop The property of the object.
* @param {ASTNode} node The corresponding node of the token.
* @param {ASTNode} node The `MemberExpression` node.
* @returns {void}
*/
function checkDotLocation(obj, prop, node) {
const dot = sourceCode.getTokenBefore(prop);
function checkDotLocation(node) {
const property = node.property;
const dot = sourceCode.getTokenBefore(property);
// `obj` expression can be parenthesized, but those paren tokens are not a part of the `obj` node.
const tokenBeforeDot = sourceCode.getTokenBefore(dot);
const textBeforeDot = sourceCode.getText().slice(tokenBeforeDot.range[1], dot.range[0]);
const textAfterDot = sourceCode.getText().slice(dot.range[1], prop.range[0]);
const textAfterDot = sourceCode.getText().slice(dot.range[1], property.range[0]);
if (onObject) {
if (!astUtils.isTokenOnSameLine(tokenBeforeDot, dot)) {
@@ -67,17 +66,17 @@ module.exports = {
context.report({
node,
loc: dot.loc.start,
loc: dot.loc,
messageId: "expectedDotAfterObject",
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], prop.range[0]], `${neededTextAfterToken}.${textBeforeDot}${textAfterDot}`)
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${neededTextAfterToken}.${textBeforeDot}${textAfterDot}`)
});
}
} else if (!astUtils.isTokenOnSameLine(dot, prop)) {
} else if (!astUtils.isTokenOnSameLine(dot, property)) {
context.report({
node,
loc: dot.loc.start,
loc: dot.loc,
messageId: "expectedDotBeforeProperty",
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], prop.range[0]], `${textBeforeDot}${textAfterDot}.`)
fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${textBeforeDot}${textAfterDot}.`)
});
}
}
@@ -89,7 +88,7 @@ module.exports = {
*/
function checkNode(node) {
if (!node.computed) {
checkDotLocation(node.object, node.property, node);
checkDotLocation(node);
}
}
+6 -6
View File
@@ -13,7 +13,7 @@ const astUtils = require("./utils/ast-utils");
/**
* Checks whether or not a given variable is a function name.
* @param {eslint-scope.Variable} variable - A variable to check.
* @param {eslint-scope.Variable} variable A variable to check.
* @returns {boolean} `true` if the variable is a function name.
*/
function isFunctionName(variable) {
@@ -73,7 +73,7 @@ module.exports = {
/**
* Returns the config option for the given node.
* @param {ASTNode} node - A node to get the config for.
* @param {ASTNode} node A node to get the config for.
* @returns {string} The config option.
*/
function getConfigForNode(node) {
@@ -91,7 +91,7 @@ module.exports = {
/**
* Determines whether the current FunctionExpression node is a get, set, or
* shorthand method in an object literal or a class.
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} True if the node is a get, set, or shorthand method.
*/
function isObjectOrClassMethod(node) {
@@ -109,7 +109,7 @@ module.exports = {
/**
* Determines whether the current FunctionExpression node has a name that would be
* inferred from context in a conforming ES6 environment.
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} True if the node would have a name assigned automatically.
*/
function hasInferredName(node) {
@@ -125,7 +125,7 @@ module.exports = {
/**
* Reports that an unnamed function should be named
* @param {ASTNode} node - The node to report in the event of an error.
* @param {ASTNode} node The node to report in the event of an error.
* @returns {void}
*/
function reportUnexpectedUnnamedFunction(node) {
@@ -139,7 +139,7 @@ module.exports = {
/**
* Reports that a named function should be unnamed
* @param {ASTNode} node - The node to report in the event of an error.
* @param {ASTNode} node The node to report in the event of an error.
* @returns {void}
*/
function reportUnexpectedNamedFunction(node) {
+5 -5
View File
@@ -40,13 +40,13 @@ module.exports = {
const checkers = {
unexpected: {
messageId: "unexpectedLineBreak",
check: (prevToken, currentToken) => prevToken.loc.start.line !== currentToken.loc.start.line,
check: (prevToken, currentToken) => prevToken.loc.end.line !== currentToken.loc.start.line,
createFix: (token, tokenBefore) => fixer =>
fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], " ")
},
missing: {
messageId: "missingLineBreak",
check: (prevToken, currentToken) => prevToken.loc.start.line === currentToken.loc.start.line,
check: (prevToken, currentToken) => prevToken.loc.end.line === currentToken.loc.start.line,
createFix: (token, tokenBefore) => fixer =>
fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], "\n")
}
@@ -61,7 +61,7 @@ module.exports = {
*/
function checkArguments(node, checker) {
for (let i = 1; i < node.arguments.length; i++) {
const prevArgToken = sourceCode.getFirstToken(node.arguments[i - 1]);
const prevArgToken = sourceCode.getLastToken(node.arguments[i - 1]);
const currentArgToken = sourceCode.getFirstToken(node.arguments[i]);
if (checker.check(prevArgToken, currentArgToken)) {
@@ -101,10 +101,10 @@ module.exports = {
} else if (option === "always") {
checkArguments(node, checkers.missing);
} else if (option === "consistent") {
const firstArgToken = sourceCode.getFirstToken(node.arguments[0]);
const firstArgToken = sourceCode.getLastToken(node.arguments[0]);
const secondArgToken = sourceCode.getFirstToken(node.arguments[1]);
if (firstArgToken.loc.start.line === secondArgToken.loc.start.line) {
if (firstArgToken.loc.end.line === secondArgToken.loc.start.line) {
checkArguments(node, checkers.unexpected);
} else {
checkArguments(node, checkers.missing);
+4 -9
View File
@@ -78,9 +78,8 @@ module.exports = {
/**
* Returns resolved option definitions based on an option and defaults
*
* @param {any} option - The option object or string value
* @param {Object} defaults - The defaults to use if options are not present
* @param {any} option The option object or string value
* @param {Object} defaults The defaults to use if options are not present
* @returns {Object} the resolved object definition
*/
function optionToDefinition(option, defaults) {
@@ -107,8 +106,7 @@ module.exports = {
/**
* Checks if the given token is a star token or not.
*
* @param {Token} token - The token to check.
* @param {Token} token The token to check.
* @returns {boolean} `true` if the token is a star token.
*/
function isStarToken(token) {
@@ -117,8 +115,7 @@ module.exports = {
/**
* Gets the generator star token of the given function node.
*
* @param {ASTNode} node - The function node to get.
* @param {ASTNode} node The function node to get.
* @returns {Token} Found star token.
*/
function getStarToken(node) {
@@ -139,7 +136,6 @@ module.exports = {
/**
* Checks the spacing between two tokens before or after the star token.
*
* @param {string} kind Either "named", "anonymous", or "method"
* @param {string} side Either "before" or "after".
* @param {Token} leftToken `function` keyword token if side is "before", or
@@ -173,7 +169,6 @@ module.exports = {
/**
* Enforces the spacing around the star if node is a generator function.
*
* @param {ASTNode} node A function expression or declaration node.
* @returns {void}
*/
+4 -7
View File
@@ -18,8 +18,7 @@ const TARGET_NODE_TYPE = /^(?:Arrow)?FunctionExpression$/u;
/**
* Checks a given code path segment is reachable.
*
* @param {CodePathSegment} segment - A segment to check.
* @param {CodePathSegment} segment A segment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -30,8 +29,7 @@ function isReachable(segment) {
* Gets a readable location.
*
* - FunctionExpression -> the function name or `function` keyword.
*
* @param {ASTNode} node - A function node to get.
* @param {ASTNode} node A function node to get.
* @returns {ASTNode|Token} The node or the token of a location.
*/
function getId(node) {
@@ -92,8 +90,7 @@ module.exports = {
*
* If the last code path segment is reachable, there are paths which are not
* returned or thrown.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {void}
*/
function checkLastSegment(node) {
@@ -113,7 +110,7 @@ module.exports = {
/**
* Checks whether a node means a getter function.
* @param {ASTNode} node - a node to check.
* @param {ASTNode} node a node to check.
* @returns {boolean} if node means a getter, return true; else return false.
*/
function isGetter(node) {
+2 -2
View File
@@ -187,6 +187,7 @@ class BinarySearchTree {
*/
class TokenInfo {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {SourceCode} sourceCode A SourceCode object
*/
@@ -236,6 +237,7 @@ class TokenInfo {
*/
class OffsetStorage {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {TokenInfo} tokenInfo a TokenInfo instance
* @param {number} indentSize The desired size of each indentation level
@@ -329,7 +331,6 @@ class OffsetStorage {
* Instead, the correct way would be to offset `baz` by 1 level from `bar`, offset `bar` by 1 level from the `)`, and
* offset the `)` by 0 levels from `foo`. This ensures that the offset between `bar` and the `)` are correctly collapsed
* in the second case.
*
* @param {Token} token The token
* @param {Token} fromToken The token that `token` should be offset from
* @param {number} offset The desired indent level
@@ -358,7 +359,6 @@ class OffsetStorage {
*
* The `setDesiredOffsets` methods inserts ranges like the ones above. The third line above would be inserted by using:
* `setDesiredOffsets([30, 43], fooToken, 1);`
*
* @param {[number, number]} range A [start, end] pair. All tokens with range[0] <= token.start < range[1] will have the offset applied.
* @param {Token} fromToken The token that this is offset from
* @param {number} offset The desired indent level
+2 -2
View File
@@ -11,7 +11,7 @@
/**
* Checks whether or not a given node is a for loop.
* @param {ASTNode} block - A node to check.
* @param {ASTNode} block A node to check.
* @returns {boolean} `true` when the node is a for loop.
*/
function isForLoop(block) {
@@ -22,7 +22,7 @@ function isForLoop(block) {
/**
* Checks whether or not a given declarator node has its initializer.
* @param {ASTNode} node - A declarator node to check.
* @param {ASTNode} node A declarator node to check.
* @returns {boolean} `true` when the node has its initializer.
*/
function isInitialized(node) {
+1 -1
View File
@@ -65,7 +65,7 @@ module.exports = {
/**
* Checks if the given string literal node uses the expected quotes
* @param {ASTNode} node - A string literal node.
* @param {ASTNode} node A string literal node.
* @returns {boolean} Whether or not the string literal used the expected quotes.
* @public
*/
+32 -56
View File
@@ -41,8 +41,7 @@ const KEYS = keywords.concat(["as", "async", "await", "from", "get", "let", "of"
/**
* Checks whether or not a given token is a "Template" token ends with "${".
*
* @param {Token} token - A token to check.
* @param {Token} token A token to check.
* @returns {boolean} `true` if the token is a "Template" token ends with "${".
*/
function isOpenParenOfTemplate(token) {
@@ -51,8 +50,7 @@ function isOpenParenOfTemplate(token) {
/**
* Checks whether or not a given token is a "Template" token starts with "}".
*
* @param {Token} token - A token to check.
* @param {Token} token A token to check.
* @returns {boolean} `true` if the token is a "Template" token starts with "}".
*/
function isCloseParenOfTemplate(token) {
@@ -88,8 +86,8 @@ module.exports = {
retv[key] = {
type: "object",
properties: {
before: { type: "boolean", default: true },
after: { type: "boolean", default: true }
before: { type: "boolean" },
after: { type: "boolean" }
},
additionalProperties: false
};
@@ -114,9 +112,8 @@ module.exports = {
/**
* Reports a given token if there are not space(s) before the token.
*
* @param {Token} token - A token to report.
* @param {RegExp} pattern - A pattern of the previous token to check.
* @param {Token} token A token to report.
* @param {RegExp} pattern A pattern of the previous token to check.
* @returns {void}
*/
function expectSpaceBefore(token, pattern) {
@@ -141,9 +138,8 @@ module.exports = {
/**
* Reports a given token if there are space(s) before the token.
*
* @param {Token} token - A token to report.
* @param {RegExp} pattern - A pattern of the previous token to check.
* @param {Token} token A token to report.
* @param {RegExp} pattern A pattern of the previous token to check.
* @returns {void}
*/
function unexpectSpaceBefore(token, pattern) {
@@ -168,9 +164,8 @@ module.exports = {
/**
* Reports a given token if there are not space(s) after the token.
*
* @param {Token} token - A token to report.
* @param {RegExp} pattern - A pattern of the next token to check.
* @param {Token} token A token to report.
* @param {RegExp} pattern A pattern of the next token to check.
* @returns {void}
*/
function expectSpaceAfter(token, pattern) {
@@ -195,9 +190,8 @@ module.exports = {
/**
* Reports a given token if there are space(s) after the token.
*
* @param {Token} token - A token to report.
* @param {RegExp} pattern - A pattern of the next token to check.
* @param {Token} token A token to report.
* @param {RegExp} pattern A pattern of the next token to check.
* @returns {void}
*/
function unexpectSpaceAfter(token, pattern) {
@@ -222,8 +216,7 @@ module.exports = {
/**
* Parses the option object and determines check methods for each keyword.
*
* @param {Object|undefined} options - The option object to parse.
* @param {Object|undefined} options The option object to parse.
* @returns {Object} - Normalized option object.
* Keys are keywords (there are for every keyword).
* Values are instances of `{"before": function, "after": function}`.
@@ -263,9 +256,8 @@ module.exports = {
/**
* Reports a given token if usage of spacing followed by the token is
* invalid.
*
* @param {Token} token - A token to report.
* @param {RegExp|undefined} pattern - Optional. A pattern of the previous
* @param {Token} token A token to report.
* @param {RegExp} [pattern] Optional. A pattern of the previous
* token to check.
* @returns {void}
*/
@@ -276,9 +268,8 @@ module.exports = {
/**
* Reports a given token if usage of spacing preceded by the token is
* invalid.
*
* @param {Token} token - A token to report.
* @param {RegExp|undefined} pattern - Optional. A pattern of the next
* @param {Token} token A token to report.
* @param {RegExp} [pattern] Optional. A pattern of the next
* token to check.
* @returns {void}
*/
@@ -288,8 +279,7 @@ module.exports = {
/**
* Reports a given token if usage of spacing around the token is invalid.
*
* @param {Token} token - A token to report.
* @param {Token} token A token to report.
* @returns {void}
*/
function checkSpacingAround(token) {
@@ -300,8 +290,7 @@ module.exports = {
/**
* Reports the first token of a given node if the first token is a keyword
* and usage of spacing around the token is invalid.
*
* @param {ASTNode|null} node - A node to report.
* @param {ASTNode|null} node A node to report.
* @returns {void}
*/
function checkSpacingAroundFirstToken(node) {
@@ -318,8 +307,7 @@ module.exports = {
*
* This is used for unary operators (e.g. `typeof`), `function`, and `super`.
* Other rules are handling usage of spacing preceded by those keywords.
*
* @param {ASTNode|null} node - A node to report.
* @param {ASTNode|null} node A node to report.
* @returns {void}
*/
function checkSpacingBeforeFirstToken(node) {
@@ -333,8 +321,7 @@ module.exports = {
/**
* Reports the previous token of a given node if the token is a keyword and
* usage of spacing around the token is invalid.
*
* @param {ASTNode|null} node - A node to report.
* @param {ASTNode|null} node A node to report.
* @returns {void}
*/
function checkSpacingAroundTokenBefore(node) {
@@ -348,8 +335,7 @@ module.exports = {
/**
* Reports `async` or `function` keywords of a given node if usage of
* spacing around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForFunction(node) {
@@ -366,8 +352,7 @@ module.exports = {
/**
* Reports `class` and `extends` keywords of a given node if usage of
* spacing around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForClass(node) {
@@ -378,8 +363,7 @@ module.exports = {
/**
* Reports `if` and `else` keywords of a given node if usage of spacing
* around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForIfStatement(node) {
@@ -390,8 +374,7 @@ module.exports = {
/**
* Reports `try`, `catch`, and `finally` keywords of a given node if usage
* of spacing around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForTryStatement(node) {
@@ -403,8 +386,7 @@ module.exports = {
/**
* Reports `do` and `while` keywords of a given node if usage of spacing
* around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForDoWhileStatement(node) {
@@ -415,8 +397,7 @@ module.exports = {
/**
* Reports `for` and `in` keywords of a given node if usage of spacing
* around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForForInStatement(node) {
@@ -427,8 +408,7 @@ module.exports = {
/**
* Reports `for` and `of` keywords of a given node if usage of spacing
* around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForForOfStatement(node) {
@@ -449,8 +429,7 @@ module.exports = {
*
* import*as A from "./a"; /*error Expected space(s) after "import".
* error Expected space(s) before "as".
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForModuleDeclaration(node) {
@@ -474,8 +453,7 @@ module.exports = {
/**
* Reports `as` keyword of a given node if usage of spacing around this
* keyword is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForImportNamespaceSpecifier(node) {
@@ -487,8 +465,7 @@ module.exports = {
/**
* Reports `static`, `get`, and `set` keywords of a given node if usage of
* spacing around those keywords is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForProperty(node) {
@@ -528,8 +505,7 @@ module.exports = {
/**
* Reports `await` keyword of a given node if usage of spacing before
* this keyword is invalid.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function checkSpacingForAwaitExpression(node) {
+1 -1
View File
@@ -131,7 +131,7 @@ module.exports = {
/**
* Check lines around directives in node
* @param {ASTNode} node - node to check
* @param {ASTNode} node node to check
* @returns {void}
*/
function checkDirectives(node) {
-5
View File
@@ -198,7 +198,6 @@ module.exports = {
/**
* Ensure that an array exists at [key] on `object`, and add `value` to it.
*
* @param {Object} object the object to mutate
* @param {string} key the object's key
* @param {*} value the value to add
@@ -214,7 +213,6 @@ module.exports = {
/**
* Retrieves an array containing all strings (" or ') in the source code.
*
* @returns {ASTNode[]} An array of string nodes.
*/
function getAllStrings() {
@@ -224,7 +222,6 @@ module.exports = {
/**
* Retrieves an array containing all template literals in the source code.
*
* @returns {ASTNode[]} An array of template literal nodes.
*/
function getAllTemplateLiterals() {
@@ -234,7 +231,6 @@ module.exports = {
/**
* Retrieves an array containing all RegExp literals in the source code.
*
* @returns {ASTNode[]} An array of RegExp literal nodes.
*/
function getAllRegExpLiterals() {
@@ -244,7 +240,6 @@ module.exports = {
/**
* A reducer to group an AST node by line number, both start and end.
*
* @param {Object} acc the accumulator
* @param {ASTNode} node the AST node in question
* @returns {Object} the modified accumulator
+3 -7
View File
@@ -61,7 +61,6 @@ module.exports = {
/**
* Reports with the first extra statement, and clears it.
*
* @returns {void}
*/
function reportFirstExtraStatementAndClear() {
@@ -81,8 +80,7 @@ module.exports = {
/**
* Gets the actual last token of a given node.
*
* @param {ASTNode} node - A node to get. This is a node except EmptyStatement.
* @param {ASTNode} node A node to get. This is a node except EmptyStatement.
* @returns {Token} The actual last token.
*/
function getActualLastToken(node) {
@@ -92,8 +90,7 @@ module.exports = {
/**
* Addresses a given node.
* It updates the state of this rule, then reports the node if the node violated this rule.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {void}
*/
function enterStatement(node) {
@@ -127,8 +124,7 @@ module.exports = {
/**
* Updates the state of this rule with the end line of leaving node to check with the next statement.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {void}
*/
function leaveStatement(node) {
+3 -3
View File
@@ -46,9 +46,9 @@ module.exports = {
/**
* Tests whether node is preceded by supplied tokens
* @param {ASTNode} node - node to check
* @param {ASTNode} parentNode - parent of node to report
* @param {boolean} expected - whether newline was expected or not
* @param {ASTNode} node node to check
* @param {ASTNode} parentNode parent of node to report
* @param {boolean} expected whether newline was expected or not
* @returns {void}
* @private
*/
+6 -7
View File
@@ -72,8 +72,7 @@ module.exports = {
* var foo = 1
*
* ;(a || b).doSomething()
*
* @param {ASTNode} node - The node to get.
* @param {ASTNode} node The node to get.
* @returns {Token} The token to compare line to the next statement.
*/
function getLastToken(node) {
@@ -93,7 +92,7 @@ module.exports = {
/**
* Determine if provided keyword is a variable declaration
* @private
* @param {string} keyword - keyword to test
* @param {string} keyword keyword to test
* @returns {boolean} True if `keyword` is a type of var
*/
function isVar(keyword) {
@@ -103,7 +102,7 @@ module.exports = {
/**
* Determine if provided keyword is a variant of for specifiers
* @private
* @param {string} keyword - keyword to test
* @param {string} keyword keyword to test
* @returns {boolean} True if `keyword` is a variant of for specifier
*/
function isForTypeSpecifier(keyword) {
@@ -113,7 +112,7 @@ module.exports = {
/**
* Determine if provided keyword is an export specifiers
* @private
* @param {string} nodeType - nodeType to test
* @param {string} nodeType nodeType to test
* @returns {boolean} True if `nodeType` is an export specifier
*/
function isExportSpecifier(nodeType) {
@@ -124,7 +123,7 @@ module.exports = {
/**
* Determine if provided node is the last of their parent block.
* @private
* @param {ASTNode} node - node to test
* @param {ASTNode} node node to test
* @returns {boolean} True if `node` is last of their parent block.
*/
function isLastNode(node) {
@@ -159,7 +158,7 @@ module.exports = {
* set to "always", or checks that there is no blank line when mode is set
* to "never"
* @private
* @param {ASTNode} node - `VariableDeclaration` node to test
* @param {ASTNode} node `VariableDeclaration` node to test
* @returns {void}
*/
function checkForBlankLine(node) {
+8 -9
View File
@@ -39,8 +39,8 @@ module.exports = {
/**
* Tests whether node is preceded by supplied tokens
* @param {ASTNode} node - node to check
* @param {Array} testTokens - array of tokens to test against
* @param {ASTNode} node node to check
* @param {Array} testTokens array of tokens to test against
* @returns {boolean} Whether or not the node is preceded by one of the supplied tokens
* @private
*/
@@ -52,7 +52,7 @@ module.exports = {
/**
* Checks whether node is the first node after statement or in block
* @param {ASTNode} node - node to check
* @param {ASTNode} node node to check
* @returns {boolean} Whether or not the node is the first node after statement or in block
* @private
*/
@@ -80,8 +80,8 @@ module.exports = {
/**
* Returns the number of lines of comments that precede the node
* @param {ASTNode} node - node to check for overlapping comments
* @param {number} lineNumTokenBefore - line number of previous token, to check for overlapping comments
* @param {ASTNode} node node to check for overlapping comments
* @param {number} lineNumTokenBefore line number of previous token, to check for overlapping comments
* @returns {number} Number of lines of comments that precede the node
* @private
*/
@@ -115,7 +115,7 @@ module.exports = {
/**
* Returns the line number of the token before the node that is passed in as an argument
* @param {ASTNode} node - The node to use as the start of the calculation
* @param {ASTNode} node The node to use as the start of the calculation
* @returns {number} Line number of the token before `node`
* @private
*/
@@ -142,7 +142,7 @@ module.exports = {
/**
* Checks whether node is preceded by a newline
* @param {ASTNode} node - node to check
* @param {ASTNode} node node to check
* @returns {boolean} Whether or not the node is preceded by a newline
* @private
*/
@@ -160,8 +160,7 @@ module.exports = {
* The fix is not considered safe if the given return statement has leading comments,
* as we cannot safely determine if the newline should be added before or after the comments.
* For more information, see: https://github.com/eslint/eslint/issues/5958#issuecomment-222767211
*
* @param {ASTNode} node - The return statement node to check.
* @param {ASTNode} node The return statement node to check.
* @returns {boolean} `true` if it can fix the node.
* @private
*/
+2 -4
View File
@@ -53,8 +53,7 @@ module.exports = {
* Get the prefix of a given MemberExpression node.
* If the MemberExpression node is a computed value it returns a
* left bracket. If not it returns a period.
*
* @param {ASTNode} node - A MemberExpression node to get
* @param {ASTNode} node A MemberExpression node to get
* @returns {string} The prefix of the node.
*/
function getPrefix(node) {
@@ -64,8 +63,7 @@ module.exports = {
/**
* Gets the property text of a given MemberExpression node.
* If the text is multiline, this returns only the first line.
*
* @param {ASTNode} node - A MemberExpression node to get.
* @param {ASTNode} node A MemberExpression node to get.
* @returns {string} The property text of the node.
*/
function getPropertyText(node) {
+2 -2
View File
@@ -33,7 +33,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
@@ -45,7 +45,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {ASTNode} node - A ClassDeclaration/ClassExpression node to check.
* @param {ASTNode} node A ClassDeclaration/ClassExpression node to check.
* @returns {void}
*/
function checkForClass(node) {
+1 -2
View File
@@ -35,8 +35,7 @@ module.exports = {
/**
* Checks a given node is -0
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {boolean} `true` if the node is -0.
*/
function isNegZero(node) {
+2 -2
View File
@@ -14,7 +14,7 @@ const astUtils = require("./utils/ast-utils.js");
/**
* Checks whether or not a node is a conditional expression.
* @param {ASTNode} node - node to test
* @param {ASTNode} node node to test
* @returns {boolean} `true` if the node is a conditional expression.
*/
function isConditional(node) {
@@ -59,7 +59,7 @@ module.exports = {
/**
* Reports if an arrow function contains an ambiguous conditional.
* @param {ASTNode} node - A node to check and report.
* @param {ASTNode} node A node to check and report.
* @returns {void}
*/
function checkArrowFunc(node) {
+4 -8
View File
@@ -54,8 +54,7 @@ module.exports = {
/**
* Checks whether the given reference is 'console' or not.
*
* @param {eslint-scope.Reference} reference - The reference to check.
* @param {eslint-scope.Reference} reference The reference to check.
* @returns {boolean} `true` if the reference is 'console'.
*/
function isConsole(reference) {
@@ -67,8 +66,7 @@ module.exports = {
/**
* Checks whether the property name of the given MemberExpression node
* is allowed by options or not.
*
* @param {ASTNode} node - The MemberExpression node to check.
* @param {ASTNode} node The MemberExpression node to check.
* @returns {boolean} `true` if the property name of the node is allowed.
*/
function isAllowed(node) {
@@ -80,8 +78,7 @@ module.exports = {
/**
* Checks whether the given reference is a member access which is not
* allowed by options or not.
*
* @param {eslint-scope.Reference} reference - The reference to check.
* @param {eslint-scope.Reference} reference The reference to check.
* @returns {boolean} `true` if the reference is a member access which
* is not allowed by options.
*/
@@ -98,8 +95,7 @@ module.exports = {
/**
* Reports the given reference as a violation.
*
* @param {eslint-scope.Reference} reference - The reference to report.
* @param {eslint-scope.Reference} reference The reference to report.
* @returns {void}
*/
function report(reference) {
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
+1 -1
View File
@@ -35,7 +35,7 @@ module.exports = {
/**
* Checks whether or not a given definition is a parameter's.
* @param {eslint-scope.DefEntry} def - A definition to check.
* @param {eslint-scope.DefEntry} def A definition to check.
* @returns {boolean} `true` if the definition is a parameter's.
*/
function isParameter(def) {
+3 -4
View File
@@ -32,8 +32,8 @@ module.exports = {
/**
* Gets state of a given member name.
* @param {string} name - A name of a member.
* @param {boolean} isStatic - A flag which specifies that is a static member.
* @param {string} name A name of a member.
* @param {boolean} isStatic A flag which specifies that is a static member.
* @returns {Object} A state of a given member name.
* - retv.init {boolean} A flag which shows the name is declared as normal member.
* - retv.get {boolean} A flag which shows the name is declared as getter.
@@ -55,8 +55,7 @@ module.exports = {
/**
* Gets the name text of a given node.
*
* @param {ASTNode} node - A node to get the name.
* @param {ASTNode} node A node to get the name.
* @returns {string} The name text of the node.
*/
function getName(node) {
+6 -5
View File
@@ -23,9 +23,10 @@ const SET_KIND = /^(?:init|set)$/u;
*/
class ObjectInfo {
// eslint-disable-next-line jsdoc/require-description
/**
* @param {ObjectInfo|null} upper - The information of the outer object.
* @param {ASTNode} node - The ObjectExpression node of this information.
* @param {ObjectInfo|null} upper The information of the outer object.
* @param {ASTNode} node The ObjectExpression node of this information.
*/
constructor(upper, node) {
this.upper = upper;
@@ -35,7 +36,7 @@ class ObjectInfo {
/**
* Gets the information of the given Property node.
* @param {ASTNode} node - The Property node to get.
* @param {ASTNode} node The Property node to get.
* @returns {{get: boolean, set: boolean}} The information of the property.
*/
getPropertyInfo(node) {
@@ -49,7 +50,7 @@ class ObjectInfo {
/**
* Checks whether the given property has been defined already or not.
* @param {ASTNode} node - The Property node to check.
* @param {ASTNode} node The Property node to check.
* @returns {boolean} `true` if the property has been defined.
*/
isPropertyDefined(node) {
@@ -63,7 +64,7 @@ class ObjectInfo {
/**
* Defines the given property.
* @param {ASTNode} node - The Property node to define.
* @param {ASTNode} node The Property node to define.
* @returns {void}
*/
defineProperty(node) {
+14 -18
View File
@@ -10,8 +10,7 @@
/**
* Returns the name of the module imported or re-exported.
*
* @param {ASTNode} node - A node to get.
* @param {ASTNode} node A node to get.
* @returns {string} the name of the module, or empty string if no name.
*/
function getValue(node) {
@@ -24,12 +23,11 @@ function getValue(node) {
/**
* Checks if the name of the import or export exists in the given array, and reports if so.
*
* @param {RuleContext} context - The ESLint rule context object.
* @param {ASTNode} node - A node to get.
* @param {string} value - The name of the imported or exported module.
* @param {string[]} array - The array containing other imports or exports in the file.
* @param {string} messageId - A messageId to be reported after the name of the module
* @param {RuleContext} context The ESLint rule context object.
* @param {ASTNode} node A node to get.
* @param {string} value The name of the imported or exported module.
* @param {string[]} array The array containing other imports or exports in the file.
* @param {string} messageId A messageId to be reported after the name of the module
*
* @returns {void} No return value
*/
@@ -47,16 +45,15 @@ function checkAndReport(context, node, value, array, messageId) {
/**
* @callback nodeCallback
* @param {ASTNode} node - A node to handle.
* @param {ASTNode} node A node to handle.
*/
/**
* Returns a function handling the imports of a given file
*
* @param {RuleContext} context - The ESLint rule context object.
* @param {boolean} includeExports - Whether or not to check for exports in addition to imports.
* @param {string[]} importsInFile - The array containing other imports in the file.
* @param {string[]} exportsInFile - The array containing other exports in the file.
* @param {RuleContext} context The ESLint rule context object.
* @param {boolean} includeExports Whether or not to check for exports in addition to imports.
* @param {string[]} importsInFile The array containing other imports in the file.
* @param {string[]} exportsInFile The array containing other exports in the file.
*
* @returns {nodeCallback} A function passed to ESLint to handle the statement.
*/
@@ -78,10 +75,9 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) {
/**
* Returns a function handling the exports of a given file
*
* @param {RuleContext} context - The ESLint rule context object.
* @param {string[]} importsInFile - The array containing other imports in the file.
* @param {string[]} exportsInFile - The array containing other exports in the file.
* @param {RuleContext} context The ESLint rule context object.
* @param {string[]} importsInFile The array containing other imports in the file.
* @param {string[]} exportsInFile The array containing other exports in the file.
*
* @returns {nodeCallback} A function passed to ESLint to handle the statement.
*/
-8
View File
@@ -58,7 +58,6 @@ module.exports = {
*
* This is not a generic function. In particular, it is assumed that the scope is a function scope or
* a function's inner scope, and that the names can be valid identifiers in the given scope.
*
* @param {string[]} names Array of variable names.
* @param {eslint-scope.Scope} scope Function scope or a function's inner scope.
* @returns {boolean} True if all names can be safely declared, false otherwise.
@@ -134,7 +133,6 @@ module.exports = {
/**
* Checks whether the removal of `else` and its braces is safe from variable name collisions.
*
* @param {Node} node The 'else' node.
* @param {eslint-scope.Scope} scope The scope in which the node and the whole 'if' statement is.
* @returns {boolean} True if it is safe, false otherwise.
@@ -171,7 +169,6 @@ module.exports = {
/**
* Display the context report if rule is violated
*
* @param {Node} node The 'else' node
* @returns {void}
*/
@@ -255,7 +252,6 @@ module.exports = {
/**
* Check to see if the node is a ReturnStatement
*
* @param {Node} node The node being evaluated
* @returns {boolean} True if node is a return
*/
@@ -267,7 +263,6 @@ module.exports = {
* Naive return checking, does not iterate through the whole
* BlockStatement because we make the assumption that the ReturnStatement
* will be the last node in the body of the BlockStatement.
*
* @param {Node} node The consequent/alternate node
* @returns {boolean} True if it has a return
*/
@@ -284,7 +279,6 @@ module.exports = {
/**
* Check to see if the node is valid for evaluation,
* meaning it has an else.
*
* @param {Node} node The node being evaluated
* @returns {boolean} True if the node is valid
*/
@@ -296,7 +290,6 @@ module.exports = {
* If the consequent is an IfStatement, check to see if it has an else
* and both its consequent and alternate path return, meaning this is
* a nested case of rule violation. If-Else not considered currently.
*
* @param {Node} node The consequent node
* @returns {boolean} True if this is a nested rule violation
*/
@@ -309,7 +302,6 @@ module.exports = {
* Check the consequent/body node to make sure it is not
* a ReturnStatement or an IfStatement that returns on both
* code paths.
*
* @param {Node} node The consequent or body node
* @returns {boolean} `true` if it is a Return/If node that always returns.
*/
+2 -4
View File
@@ -28,8 +28,7 @@ const ALLOW_OPTIONS = Object.freeze([
/**
* Gets the kind of a given function node.
*
* @param {ASTNode} node - A function node to get. This is one of
* @param {ASTNode} node A function node to get. This is one of
* an ArrowFunctionExpression, a FunctionDeclaration, or a
* FunctionExpression.
* @returns {string} The kind of the function. This is one of "functions",
@@ -130,8 +129,7 @@ module.exports = {
* - Not allowed by options.
* - The body is empty.
* - The body doesn't have any comments.
*
* @param {ASTNode} node - A function node to report. This is one of
* @param {ASTNode} node A function node to report. This is one of
* an ArrowFunctionExpression, a FunctionDeclaration, or a
* FunctionExpression.
* @returns {void}
+10 -18
View File
@@ -22,9 +22,8 @@ const candidatesOfGlobalObject = Object.freeze([
/**
* Checks a given node is a Identifier node of the specified name.
*
* @param {ASTNode} node - A node to check.
* @param {string} name - A name to check.
* @param {ASTNode} node A node to check.
* @param {string} name A name to check.
* @returns {boolean} `true` if the node is a Identifier node of the name.
*/
function isIdentifier(node, name) {
@@ -33,9 +32,8 @@ function isIdentifier(node, name) {
/**
* Checks a given node is a Literal node of the specified string value.
*
* @param {ASTNode} node - A node to check.
* @param {string} name - A name to check.
* @param {ASTNode} node A node to check.
* @param {string} name A name to check.
* @returns {boolean} `true` if the node is a Literal node of the name.
*/
function isConstant(node, name) {
@@ -57,9 +55,8 @@ function isConstant(node, name) {
/**
* Checks a given node is a MemberExpression node which has the specified name's
* property.
*
* @param {ASTNode} node - A node to check.
* @param {string} name - A name to check.
* @param {ASTNode} node A node to check.
* @param {string} name A name to check.
* @returns {boolean} `true` if the node is a MemberExpression node which has
* the specified name's property
*/
@@ -113,8 +110,7 @@ module.exports = {
*
* This is used in order to check whether or not `this` binding is a
* reference to the global object.
*
* @param {ASTNode} node - A node of the scope. This is one of Program,
* @param {ASTNode} node A node of the scope. This is one of Program,
* FunctionDeclaration, FunctionExpression, and ArrowFunctionExpression.
* @returns {void}
*/
@@ -132,7 +128,6 @@ module.exports = {
/**
* Pops a variable scope from the stack.
*
* @returns {void}
*/
function exitVarScope() {
@@ -148,8 +143,7 @@ module.exports = {
* The location of the report is always `eval` `Identifier` (or possibly
* `Literal`). The type of the report is `CallExpression` if the parent is
* `CallExpression`. Otherwise, it's the given node type.
*
* @param {ASTNode} node - A node to report.
* @param {ASTNode} node A node to report.
* @returns {void}
*/
function report(node) {
@@ -171,8 +165,7 @@ module.exports = {
/**
* Reports accesses of `eval` via the global object.
*
* @param {eslint-scope.Scope} globalScope - The global scope.
* @param {eslint-scope.Scope} globalScope The global scope.
* @returns {void}
*/
function reportAccessingEvalViaGlobalObject(globalScope) {
@@ -205,8 +198,7 @@ module.exports = {
/**
* Reports all accesses of `eval` (excludes direct calls to eval).
*
* @param {eslint-scope.Scope} globalScope - The global scope.
* @param {eslint-scope.Scope} globalScope The global scope.
* @returns {void}
*/
function reportAccessingEval(globalScope) {
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
+5 -12
View File
@@ -47,7 +47,6 @@ module.exports = {
* Checks if a node is free of side effects.
*
* This check is stricter than it needs to be, in order to keep the implementation simple.
*
* @param {ASTNode} node A node to check.
* @returns {boolean} True if the node is known to be side-effect free, false otherwise.
*/
@@ -57,8 +56,7 @@ module.exports = {
/**
* Reports a given function node.
*
* @param {ASTNode} node - A node to report. This is a FunctionExpression or
* @param {ASTNode} node A node to report. This is a FunctionExpression or
* an ArrowFunctionExpression.
* @returns {void}
*/
@@ -90,8 +88,7 @@ module.exports = {
* method.
*
* e.g. `(function() {}.bind(foo))`
*
* @param {ASTNode} node - A node to report. This is a FunctionExpression or
* @param {ASTNode} node A node to report. This is a FunctionExpression or
* an ArrowFunctionExpression.
* @returns {boolean} `true` if the node is the callee of `.bind()` method.
*/
@@ -113,8 +110,7 @@ module.exports = {
/**
* Adds a scope information object to the stack.
*
* @param {ASTNode} node - A node to add. This node is a FunctionExpression
* @param {ASTNode} node A node to add. This node is a FunctionExpression
* or a FunctionDeclaration node.
* @returns {void}
*/
@@ -130,8 +126,7 @@ module.exports = {
* Removes the scope information object from the top of the stack.
* At the same time, this reports the function node if the function has
* `.bind()` and the `this` keywords found.
*
* @param {ASTNode} node - A node to remove. This node is a
* @param {ASTNode} node A node to remove. This node is a
* FunctionExpression or a FunctionDeclaration node.
* @returns {void}
*/
@@ -146,8 +141,7 @@ module.exports = {
/**
* Reports a given arrow function if the function is callee of `.bind()`
* method.
*
* @param {ASTNode} node - A node to report. This node is an
* @param {ASTNode} node A node to report. This node is an
* ArrowFunctionExpression.
* @returns {void}
*/
@@ -159,7 +153,6 @@ module.exports = {
/**
* Set the mark as the `this` keyword was found in this scope.
*
* @returns {void}
*/
function markAsThisFound() {
-2
View File
@@ -49,7 +49,6 @@ module.exports = {
/**
* Check if a node is in a context where its value would be coerced to a boolean at runtime.
*
* @param {ASTNode} node The node
* @param {ASTNode} parent Its parent
* @returns {boolean} If it is in a boolean context
@@ -67,7 +66,6 @@ module.exports = {
/**
* Check if a node has comments inside.
*
* @param {ASTNode} node The node to check.
* @returns {boolean} `true` if it has comments inside.
*/
+4 -9
View File
@@ -40,8 +40,7 @@ module.exports = {
/**
* Creates a new scope with a breakable statement.
*
* @param {ASTNode} node - A node to create. This is a BreakableStatement.
* @param {ASTNode} node A node to create. This is a BreakableStatement.
* @returns {void}
*/
function enterBreakableStatement(node) {
@@ -54,7 +53,6 @@ module.exports = {
/**
* Removes the top scope of the stack.
*
* @returns {void}
*/
function exitBreakableStatement() {
@@ -66,8 +64,7 @@ module.exports = {
*
* This ignores it if the body is a breakable statement.
* In this case it's handled in the `enterBreakableStatement` function.
*
* @param {ASTNode} node - A node to create. This is a LabeledStatement.
* @param {ASTNode} node A node to create. This is a LabeledStatement.
* @returns {void}
*/
function enterLabeledStatement(node) {
@@ -85,8 +82,7 @@ module.exports = {
*
* This ignores it if the body is a breakable statement.
* In this case it's handled in the `exitBreakableStatement` function.
*
* @param {ASTNode} node - A node. This is a LabeledStatement.
* @param {ASTNode} node A node. This is a LabeledStatement.
* @returns {void}
*/
function exitLabeledStatement(node) {
@@ -97,8 +93,7 @@ module.exports = {
/**
* Reports a given control node if it's unnecessary.
*
* @param {ASTNode} node - A node. This is a BreakStatement or a
* @param {ASTNode} node A node. This is a BreakStatement or a
* ContinueStatement.
* @returns {void}
*/
+17 -15
View File
@@ -50,7 +50,8 @@ module.exports = {
returnAssign: { type: "boolean" },
ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
enforceForArrowConditionals: { type: "boolean" },
enforceForSequenceExpressions: { type: "boolean" }
enforceForSequenceExpressions: { type: "boolean" },
enforceForNewInMemberExpressions: { type: "boolean" }
},
additionalProperties: false
}
@@ -80,6 +81,8 @@ module.exports = {
context.options[1].enforceForArrowConditionals === false;
const IGNORE_SEQUENCE_EXPRESSIONS = ALL_NODES && context.options[1] &&
context.options[1].enforceForSequenceExpressions === false;
const IGNORE_NEW_IN_MEMBER_EXPR = ALL_NODES && context.options[1] &&
context.options[1].enforceForNewInMemberExpressions === false;
const PRECEDENCE_OF_ASSIGNMENT_EXPR = precedence({ type: "AssignmentExpression" });
const PRECEDENCE_OF_UPDATE_EXPR = precedence({ type: "UpdateExpression" });
@@ -88,7 +91,7 @@ module.exports = {
/**
* Determines if this rule should be enforced for a node given the current configuration.
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the rule should be enforced for this node.
* @private
*/
@@ -127,7 +130,7 @@ module.exports = {
/**
* Determines if a node is surrounded by parentheses.
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is parenthesised.
* @private
*/
@@ -137,7 +140,7 @@ module.exports = {
/**
* Determines if a node is surrounded by parentheses twice.
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is doubly parenthesised.
* @private
*/
@@ -147,7 +150,7 @@ module.exports = {
/**
* Determines if a node is surrounded by (potentially) invalid parentheses.
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is incorrectly parenthesised.
* @private
*/
@@ -158,7 +161,7 @@ module.exports = {
/**
* Determines if a node that is expected to be parenthesised is surrounded by
* (potentially) invalid extra parentheses.
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is has an unexpected extra pair of parentheses.
* @private
*/
@@ -168,7 +171,7 @@ module.exports = {
/**
* Determines if a node test expression is allowed to have a parenthesised assignment
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the assignment can be parenthesised.
* @private
*/
@@ -178,7 +181,7 @@ module.exports = {
/**
* Determines if a node is in a return statement
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is in a return statement.
* @private
*/
@@ -197,7 +200,7 @@ module.exports = {
/**
* Determines if a constructor function is newed-up with parens
* @param {ASTNode} newExpression - The NewExpression node to be checked.
* @param {ASTNode} newExpression The NewExpression node to be checked.
* @returns {boolean} True if the constructor is called with parens.
* @private
*/
@@ -217,7 +220,7 @@ module.exports = {
/**
* Determines if a node is or contains an assignment expression
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is or contains an assignment expression.
* @private
*/
@@ -239,7 +242,7 @@ module.exports = {
/**
* Determines if a node is contained by or is itself a return statement and is allowed to have a parenthesised assignment
* @param {ASTNode} node - The node to be checked.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the assignment can be parenthesised.
* @private
*/
@@ -261,8 +264,8 @@ module.exports = {
/**
* Determines if a node following a [no LineTerminator here] restriction is
* surrounded by (potentially) invalid extra parentheses.
* @param {Token} token - The token preceding the [no LineTerminator here] restriction.
* @param {ASTNode} node - The node to be checked.
* @param {Token} token The token preceding the [no LineTerminator here] restriction.
* @param {ASTNode} node The node to be checked.
* @returns {boolean} True if the node is incorrectly parenthesised.
* @private
*/
@@ -567,7 +570,6 @@ module.exports = {
/**
* Checks whether the syntax of the given ancestor of an 'in' expression inside a for-loop initializer
* is preventing the 'in' keyword from being interpreted as a part of an ill-formed for-in loop.
*
* @param {ASTNode} node Ancestor of an 'in' expression.
* @param {ASTNode} child Child of the node, ancestor of the same 'in' expression or the 'in' expression itself.
* @returns {boolean} True if the keyword 'in' would be interpreted as the 'in' operator, without any parenthesis.
@@ -599,7 +601,6 @@ module.exports = {
/**
* Starts a new reports buffering. Warnings will be stored in a buffer instead of being reported immediately.
* An additional logic that requires multiple nodes (e.g. a whole subtree) may dismiss some of the stored warnings.
*
* @returns {void}
*/
function startNewReportsBuffering() {
@@ -895,6 +896,7 @@ module.exports = {
}
if (nodeObjHasExcessParens &&
!IGNORE_NEW_IN_MEMBER_EXPR &&
node.object.type === "NewExpression" &&
isNewExpressionWithParens(node.object)) {
report(node.object);
+5 -6
View File
@@ -40,7 +40,7 @@ module.exports = {
/**
* Reports an unnecessary semicolon error.
* @param {Node|Token} nodeOrToken - A node or a token to be reported.
* @param {Node|Token} nodeOrToken A node or a token to be reported.
* @returns {void}
*/
function report(nodeOrToken) {
@@ -64,8 +64,7 @@ module.exports = {
/**
* Checks for a part of a class body.
* This checks tokens from a specified token to a next MethodDefinition or the end of class body.
*
* @param {Token} firstToken - The first token to check.
* @param {Token} firstToken The first token to check.
* @returns {void}
*/
function checkForPartOfClassBody(firstToken) {
@@ -83,7 +82,7 @@ module.exports = {
/**
* Reports this empty statement, except if the parent node is a loop.
* @param {Node} node - A EmptyStatement node to be reported.
* @param {Node} node A EmptyStatement node to be reported.
* @returns {void}
*/
EmptyStatement(node) {
@@ -106,7 +105,7 @@ module.exports = {
/**
* Checks tokens from the head of this class body to the first MethodDefinition or the end of this class body.
* @param {Node} node - A ClassBody node to check.
* @param {Node} node A ClassBody node to check.
* @returns {void}
*/
ClassBody(node) {
@@ -115,7 +114,7 @@ module.exports = {
/**
* Checks tokens from this MethodDefinition to the next MethodDefinition or the end of this class body.
* @param {Node} node - A MethodDefinition node of the start point.
* @param {Node} node A MethodDefinition node of the start point.
* @returns {void}
*/
MethodDefinition(node) {
+6 -6
View File
@@ -18,9 +18,9 @@ const DEFAULT_FALLTHROUGH_COMMENT = /falls?\s?through/iu;
/**
* Checks whether or not a given node has a fallthrough comment.
* @param {ASTNode} node - A SwitchCase node to get comments.
* @param {RuleContext} context - A rule context which stores comments.
* @param {RegExp} fallthroughCommentPattern - A pattern to match comment to.
* @param {ASTNode} node A SwitchCase node to get comments.
* @param {RuleContext} context A rule context which stores comments.
* @param {RegExp} fallthroughCommentPattern A pattern to match comment to.
* @returns {boolean} `true` if the node has a valid fallthrough comment.
*/
function hasFallthroughComment(node, context, fallthroughCommentPattern) {
@@ -32,7 +32,7 @@ function hasFallthroughComment(node, context, fallthroughCommentPattern) {
/**
* Checks whether or not a given code path segment is reachable.
* @param {CodePathSegment} segment - A CodePathSegment to check.
* @param {CodePathSegment} segment A CodePathSegment to check.
* @returns {boolean} `true` if the segment is reachable.
*/
function isReachable(segment) {
@@ -41,8 +41,8 @@ function isReachable(segment) {
/**
* Checks whether a node and a token are separated by blank lines
* @param {ASTNode} node - The node to check
* @param {Token} token - The token to compare against
* @param {ASTNode} node The node to check
* @param {Token} token The token to compare against
* @returns {boolean} `true` if there are blank lines between node and token
*/
function hasBlankLinesBetween(node, token) {
+3 -3
View File
@@ -29,7 +29,7 @@ module.exports = {
/**
* Reports a reference if is non initializer and writable.
* @param {References} references - Collection of reference to check.
* @param {References} references Collection of reference to check.
* @returns {void}
*/
function checkReference(references) {
@@ -40,7 +40,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
@@ -51,7 +51,7 @@ module.exports = {
/**
* Checks parameters of a given function node.
* @param {ASTNode} node - A function node to check.
* @param {ASTNode} node A function node to check.
* @returns {void}
*/
function checkForFunction(node) {
+4 -4
View File
@@ -41,9 +41,9 @@ module.exports = {
/**
* Reports write references.
* @param {Reference} reference - A reference to check.
* @param {int} index - The index of the reference in the references.
* @param {Reference[]} references - The array that the reference belongs to.
* @param {Reference} reference A reference to check.
* @param {int} index The index of the reference in the references.
* @param {Reference[]} references The array that the reference belongs to.
* @returns {void}
*/
function checkReference(reference, index, references) {
@@ -68,7 +68,7 @@ module.exports = {
/**
* Reports write references if a given variable is read-only builtin.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
+10 -10
View File
@@ -16,7 +16,7 @@ const ALLOWABLE_OPERATORS = ["~", "!!", "+", "*"];
/**
* Parses and normalizes an option object.
* @param {Object} options - An option object to parse.
* @param {Object} options An option object to parse.
* @returns {Object} The parsed and normalized option object.
*/
function parseOptions(options) {
@@ -30,7 +30,7 @@ function parseOptions(options) {
/**
* Checks whether or not a node is a double logical nigating.
* @param {ASTNode} node - An UnaryExpression node to check.
* @param {ASTNode} node An UnaryExpression node to check.
* @returns {boolean} Whether or not the node is a double logical nigating.
*/
function isDoubleLogicalNegating(node) {
@@ -43,7 +43,7 @@ function isDoubleLogicalNegating(node) {
/**
* Checks whether or not a node is a binary negating of `.indexOf()` method calling.
* @param {ASTNode} node - An UnaryExpression node to check.
* @param {ASTNode} node An UnaryExpression node to check.
* @returns {boolean} Whether or not the node is a binary negating of `.indexOf()` method calling.
*/
function isBinaryNegatingOfIndexOf(node) {
@@ -58,7 +58,7 @@ function isBinaryNegatingOfIndexOf(node) {
/**
* Checks whether or not a node is a multiplying by one.
* @param {BinaryExpression} node - A BinaryExpression node to check.
* @param {BinaryExpression} node A BinaryExpression node to check.
* @returns {boolean} Whether or not the node is a multiplying by one.
*/
function isMultiplyByOne(node) {
@@ -118,7 +118,7 @@ function isEmptyString(node) {
/**
* Checks whether or not a node is a concatenating with an empty string.
* @param {ASTNode} node - A BinaryExpression node to check.
* @param {ASTNode} node A BinaryExpression node to check.
* @returns {boolean} Whether or not the node is a concatenating with an empty string.
*/
function isConcatWithEmptyString(node) {
@@ -130,7 +130,7 @@ function isConcatWithEmptyString(node) {
/**
* Checks whether or not a node is appended with an empty string.
* @param {ASTNode} node - An AssignmentExpression node to check.
* @param {ASTNode} node An AssignmentExpression node to check.
* @returns {boolean} Whether or not the node is appended with an empty string.
*/
function isAppendEmptyString(node) {
@@ -139,7 +139,7 @@ function isAppendEmptyString(node) {
/**
* Returns the operand that is not an empty string from a flagged BinaryExpression.
* @param {ASTNode} node - The flagged BinaryExpression node to check.
* @param {ASTNode} node The flagged BinaryExpression node to check.
* @returns {ASTNode} The operand that is not an empty string from a flagged BinaryExpression.
*/
function getNonEmptyOperand(node) {
@@ -196,9 +196,9 @@ module.exports = {
/**
* Reports an error and autofixes the node
* @param {ASTNode} node - An ast node to report the error on.
* @param {string} recommendation - The recommended code for the issue
* @param {bool} shouldFix - Whether this report should fix the node
* @param {ASTNode} node An ast node to report the error on.
* @param {string} recommendation The recommended code for the issue
* @param {bool} shouldFix Whether this report should fix the node
* @returns {void}
*/
function report(node, recommendation, shouldFix) {
-1
View File
@@ -64,7 +64,6 @@ module.exports = {
* Determines if a node represents a call to a potentially implied eval.
*
* This checks the callee name and that there's an argument, but not the type of the argument.
*
* @param {ASTNode} node The CallExpression to check.
* @returns {boolean} True if the node matches, false if not.
* @private
+1 -3
View File
@@ -38,7 +38,6 @@ module.exports = {
*
* The return value has a flag that whether or not `this` keyword is valid.
* The flag is initialized when got at the first time.
*
* @returns {{valid: boolean}}
* an object which has a flag that whether or not `this` keyword is valid.
*/
@@ -61,8 +60,7 @@ module.exports = {
* The checking context is not initialized yet.
* Because most functions don't have `this` keyword.
* When `this` keyword was found, the checking context is initialized.
*
* @param {ASTNode} node - A function node that was entered.
* @param {ASTNode} node A function node that was entered.
* @returns {void}
*/
function enterFunction(node) {
+3 -6
View File
@@ -51,8 +51,7 @@ module.exports = {
/**
* Gets the kind of a given node.
*
* @param {ASTNode} node - A node to get.
* @param {ASTNode} node A node to get.
* @returns {string} The kind of the node.
*/
function getBodyKind(node) {
@@ -67,8 +66,7 @@ module.exports = {
/**
* Checks whether the label of a given kind is allowed or not.
*
* @param {string} kind - A kind to check.
* @param {string} kind A kind to check.
* @returns {boolean} `true` if the kind is allowed.
*/
function isAllowed(kind) {
@@ -81,8 +79,7 @@ module.exports = {
/**
* Checks whether a given name is a label of a loop or not.
*
* @param {string} label - A name of a label to check.
* @param {string} label A name of a label to check.
* @returns {boolean} `true` if the name is a label of a loop.
*/
function getKind(label) {
+1 -1
View File
@@ -31,7 +31,7 @@ module.exports = {
/**
* Reports a node as invalid.
* @param {ASTNode} node - The node to be reported.
* @param {ASTNode} node The node to be reported.
* @returns {void}
*/
function report(node) {
+6 -11
View File
@@ -14,8 +14,7 @@
*
* We don't need to check nested functions, so this ignores those.
* `Scope.through` contains references of nested functions.
*
* @param {ASTNode} node - An AST node to get.
* @param {ASTNode} node An AST node to get.
* @returns {ASTNode|null} The containing loop node of the specified node, or
* `null`.
*/
@@ -63,9 +62,8 @@ function getContainingLoopNode(node) {
/**
* Gets the containing loop node of a given node.
* If the loop was nested, this returns the most outer loop.
*
* @param {ASTNode} node - A node to get. This is a loop node.
* @param {ASTNode|null} excludedNode - A node that the result node should not
* @param {ASTNode} node A node to get. This is a loop node.
* @param {ASTNode|null} excludedNode A node that the result node should not
* include.
* @returns {ASTNode} The most outer loop node.
*/
@@ -85,9 +83,8 @@ function getTopLoopNode(node, excludedNode) {
/**
* Checks whether a given reference which refers to an upper scope's variable is
* safe or not.
*
* @param {ASTNode} loopNode - A containing loop node.
* @param {eslint-scope.Reference} reference - A reference to check.
* @param {ASTNode} loopNode A containing loop node.
* @param {eslint-scope.Reference} reference A reference to check.
* @returns {boolean} `true` if the reference is safe or not.
*/
function isSafe(loopNode, reference) {
@@ -131,8 +128,7 @@ function isSafe(loopNode, reference) {
* It's safeafe if the reference matches one of the following condition.
* - is readonly.
* - doesn't exist inside a local function and after the border.
*
* @param {eslint-scope.Reference} upperRef - A reference to check.
* @param {eslint-scope.Reference} upperRef A reference to check.
* @returns {boolean} `true` if the reference is safe.
*/
function isSafeReference(upperRef) {
@@ -177,7 +173,6 @@ module.exports = {
*
* - has a loop node in ancestors.
* - has any references which refers to an unsafe variable.
*
* @param {ASTNode} node The AST node to check.
* @returns {boolean} Whether or not the node is within a loop.
*/
+6 -6
View File
@@ -61,7 +61,7 @@ module.exports = {
/**
* Returns whether the node is number literal
* @param {Node} node - the node literal being evaluated
* @param {Node} node the node literal being evaluated
* @returns {boolean} true if the node is a number literal
*/
function isNumber(node) {
@@ -70,7 +70,7 @@ module.exports = {
/**
* Returns whether the number should be ignored
* @param {number} num - the number
* @param {number} num the number
* @returns {boolean} true if the number should be ignored
*/
function shouldIgnoreNumber(num) {
@@ -79,8 +79,8 @@ module.exports = {
/**
* Returns whether the number should be ignored when used as a radix within parseInt() or Number.parseInt()
* @param {ASTNode} parent - the non-"UnaryExpression" parent
* @param {ASTNode} node - the node literal being evaluated
* @param {ASTNode} parent the non-"UnaryExpression" parent
* @param {ASTNode} node the node literal being evaluated
* @returns {boolean} true if the number should be ignored
*/
function shouldIgnoreParseInt(parent, node) {
@@ -93,7 +93,7 @@ module.exports = {
/**
* Returns whether the number should be ignored when used to define a JSX prop
* @param {ASTNode} parent - the non-"UnaryExpression" parent
* @param {ASTNode} parent the non-"UnaryExpression" parent
* @returns {boolean} true if the number should be ignored
*/
function shouldIgnoreJSXNumbers(parent) {
@@ -102,7 +102,7 @@ module.exports = {
/**
* Returns whether the number should be ignored when used as an array index with enabled 'ignoreArrayIndexes' option.
* @param {ASTNode} parent - the non-"UnaryExpression" parent.
* @param {ASTNode} parent the non-"UnaryExpression" parent.
* @returns {boolean} true if the number should be ignored
*/
function shouldIgnoreArrayIndexes(parent) {
+14 -7
View File
@@ -16,7 +16,6 @@ const { isCombiningCharacter, isEmojiModifier, isRegionalIndicatorSymbol, isSurr
*
* CharacterClassRange syntax can steal a part of character sequence,
* so this function reverts CharacterClassRange syntax and restore the sequence.
*
* @param {regexpp.AST.CharacterClassElement[]} nodes The node list to iterate character sequences.
* @returns {IterableIterator<number[]>} The list of character sequences.
*/
@@ -131,12 +130,6 @@ module.exports = {
* @returns {void}
*/
function verify(node, pattern, flags) {
const patternNode = parser.parsePattern(
pattern,
0,
pattern.length,
flags.includes("u")
);
const has = {
surrogatePairWithoutUFlag: false,
combiningClass: false,
@@ -145,6 +138,20 @@ module.exports = {
regionalIndicatorSymbol: false,
zwj: false
};
let patternNode;
try {
patternNode = parser.parsePattern(
pattern,
0,
pattern.length,
flags.includes("u")
);
} catch (e) {
// Ignore regular expressions with syntax errors
return;
}
visitRegExpAST(patternNode, {
onCharacterClassEnter(ccNode) {
+13 -22
View File
@@ -40,8 +40,7 @@ const TARGET_NODE_TYPE = /^(?:Binary|Logical|Conditional)Expression$/u;
/**
* Normalizes options.
*
* @param {Object|undefined} options - A options object to normalize.
* @param {Object|undefined} options A options object to normalize.
* @returns {Object} Normalized option object.
*/
function normalizeOptions(options = {}) {
@@ -57,10 +56,9 @@ function normalizeOptions(options = {}) {
/**
* Checks whether any group which includes both given operator exists or not.
*
* @param {Array.<string[]>} groups - A list of groups to check.
* @param {string} left - An operator.
* @param {string} right - Another operator.
* @param {Array.<string[]>} groups A list of groups to check.
* @param {string} left An operator.
* @param {string} right Another operator.
* @returns {boolean} `true` if such group existed.
*/
function includesBothInAGroup(groups, left, right) {
@@ -69,8 +67,7 @@ function includesBothInAGroup(groups, left, right) {
/**
* Checks whether the given node is a conditional expression and returns the test node else the left node.
*
* @param {ASTNode} node - A node which can be a BinaryExpression or a LogicalExpression node.
* @param {ASTNode} node A node which can be a BinaryExpression or a LogicalExpression node.
* This parent node can be BinaryExpression, LogicalExpression
* , or a ConditionalExpression node
* @returns {ASTNode} node the appropriate node(left or test).
@@ -124,8 +121,7 @@ module.exports = {
/**
* Checks whether a given node should be ignored by options or not.
*
* @param {ASTNode} node - A node to check. This is a BinaryExpression
* @param {ASTNode} node A node to check. This is a BinaryExpression
* node or a LogicalExpression node. This parent node is one of
* them, too.
* @returns {boolean} `true` if the node should be ignored.
@@ -146,8 +142,7 @@ module.exports = {
/**
* Checks whether the operator of a given node is mixed with parent
* node's operator or not.
*
* @param {ASTNode} node - A node to check. This is a BinaryExpression
* @param {ASTNode} node A node to check. This is a BinaryExpression
* node or a LogicalExpression node. This parent node is one of
* them, too.
* @returns {boolean} `true` if the node was mixed.
@@ -163,8 +158,7 @@ module.exports = {
/**
* Checks whether the operator of a given node is mixed with a
* conditional expression.
*
* @param {ASTNode} node - A node to check. This is a conditional
* @param {ASTNode} node A node to check. This is a conditional
* expression node
* @returns {boolean} `true` if the node was mixed.
*/
@@ -174,8 +168,7 @@ module.exports = {
/**
* Gets the operator token of a given node.
*
* @param {ASTNode} node - A node to check. This is a BinaryExpression
* @param {ASTNode} node A node to check. This is a BinaryExpression
* node or a LogicalExpression node.
* @returns {Token} The operator token of the node.
*/
@@ -186,8 +179,7 @@ module.exports = {
/**
* Reports both the operator of a given node and the operator of the
* parent node.
*
* @param {ASTNode} node - A node to check. This is a BinaryExpression
* @param {ASTNode} node A node to check. This is a BinaryExpression
* node or a LogicalExpression node. This parent node is one of
* them, too.
* @returns {void}
@@ -205,13 +197,13 @@ module.exports = {
context.report({
node: left,
loc: getOperatorToken(left).loc.start,
loc: getOperatorToken(left).loc,
message,
data
});
context.report({
node: right,
loc: getOperatorToken(right).loc.start,
loc: getOperatorToken(right).loc,
message,
data
});
@@ -220,8 +212,7 @@ module.exports = {
/**
* Checks between the operator of this node and the operator of the
* parent node.
*
* @param {ASTNode} node - A node to check.
* @param {ASTNode} node A node to check.
* @returns {void}
*/
function check(node) {
-1
View File
@@ -58,7 +58,6 @@ module.exports = {
/**
* Returns the list of built-in modules.
*
* @returns {string[]} An array of built-in Node.js modules.
*/
function getBuiltinModules() {
+1 -1
View File
@@ -121,7 +121,7 @@ module.exports = {
context.report({
node: rightToken,
loc: rightToken.loc.start,
loc: { start: leftToken.loc.end, end: rightToken.loc.start },
message: "Multiple spaces found before '{{displayValue}}'.",
data: { displayValue },
fix: fixer => fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], " ")
+4 -4
View File
@@ -46,9 +46,9 @@ module.exports = {
/**
* Reports write references.
* @param {Reference} reference - A reference to check.
* @param {int} index - The index of the reference in the references.
* @param {Reference[]} references - The array that the reference belongs to.
* @param {Reference} reference A reference to check.
* @param {int} index The index of the reference in the references.
* @param {Reference[]} references The array that the reference belongs to.
* @returns {void}
*/
function checkReference(reference, index, references) {
@@ -73,7 +73,7 @@ module.exports = {
/**
* Reports write references if a given variable is read-only builtin.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
+28 -7
View File
@@ -45,6 +45,13 @@ module.exports = {
type: "string"
},
uniqueItems: true
},
ignorePropertyModificationsForRegex: {
type: "array",
items: {
type: "string"
},
uniqueItems: true
}
},
additionalProperties: false
@@ -57,10 +64,11 @@ module.exports = {
create(context) {
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 || [];
/**
* Checks whether or not the reference modifies properties of its variable.
* @param {Reference} reference - A reference to check.
* @param {Reference} reference A reference to check.
* @returns {boolean} Whether or not the reference modifies properties of its variable.
*/
function isModifyingProp(reference) {
@@ -136,11 +144,24 @@ module.exports = {
return false;
}
/**
* Tests that an identifier name matches any of the ignored property assignments.
* First we test strings in ignoredPropertyAssignmentsFor.
* Then we instantiate and test RegExp objects from ignoredPropertyAssignmentsForRegex strings.
* @param {string} identifierName A string that describes the name of an identifier to
* ignore property assignments for.
* @returns {boolean} Whether the string matches an ignored property assignment regular expression or not.
*/
function isIgnoredPropertyAssignment(identifierName) {
return ignoredPropertyAssignmentsFor.includes(identifierName) ||
ignoredPropertyAssignmentsForRegex.some(ignored => new RegExp(ignored, "u").test(identifierName));
}
/**
* Reports a reference if is non initializer and writable.
* @param {Reference} reference - A reference to check.
* @param {int} index - The index of the reference in the references.
* @param {Reference[]} references - The array that the reference belongs to.
* @param {Reference} reference A reference to check.
* @param {int} index The index of the reference in the references.
* @param {Reference[]} references The array that the reference belongs to.
* @returns {void}
*/
function checkReference(reference, index, references) {
@@ -157,7 +178,7 @@ module.exports = {
) {
if (reference.isWrite()) {
context.report({ node: identifier, message: "Assignment to function parameter '{{name}}'.", data: { name: identifier.name } });
} else if (props && isModifyingProp(reference) && ignoredPropertyAssignmentsFor.indexOf(identifier.name) === -1) {
} else if (props && isModifyingProp(reference) && !isIgnoredPropertyAssignment(identifier.name)) {
context.report({ node: identifier, message: "Assignment to property of function parameter '{{name}}'.", data: { name: identifier.name } });
}
}
@@ -165,7 +186,7 @@ module.exports = {
/**
* Finds and reports references that are non initializer and writable.
* @param {Variable} variable - A variable to check.
* @param {Variable} variable A variable to check.
* @returns {void}
*/
function checkVariable(variable) {
@@ -176,7 +197,7 @@ module.exports = {
/**
* Checks parameters of a given function node.
* @param {ASTNode} node - A function node to check.
* @param {ASTNode} node A function node to check.
* @returns {void}
*/
function checkForFunction(node) {
+1 -1
View File
@@ -86,7 +86,7 @@ module.exports = {
/**
* Find variables in a given scope and flag redeclared ones.
* @param {Scope} scope - An eslint-scope scope object.
* @param {Scope} scope An eslint-scope scope object.
* @returns {void}
* @private
*/
-1
View File
@@ -52,7 +52,6 @@ module.exports = {
/**
* Validate regular expression
*
* @param {ASTNode} nodeToReport Node to report.
* @param {string} pattern Regular expression pattern to validate.
* @param {string} rawPattern Raw representation of the pattern in the source code.
+11 -11
View File
@@ -116,7 +116,7 @@ module.exports = {
/**
* Checks to see if "*" is being used to import everything.
* @param {Set.<string>} importNames - Set of import names that are being imported
* @param {Set.<string>} importNames Set of import names that are being imported
* @returns {boolean} whether everything is imported or not
*/
function isEverythingImported(importNames) {
@@ -145,7 +145,7 @@ module.exports = {
/**
* Report a restricted path specifically for patterns.
* @param {node} node - representing the restricted path reference
* @param {node} node representing the restricted path reference
* @returns {void}
* @private
*/
@@ -163,8 +163,8 @@ module.exports = {
/**
* Report a restricted path specifically when using the '*' import.
* @param {string} importSource - path of the import
* @param {node} node - representing the restricted path reference
* @param {string} importSource path of the import
* @param {node} node representing the restricted path reference
* @returns {void}
* @private
*/
@@ -185,8 +185,8 @@ module.exports = {
/**
* Check if the given importSource is restricted because '*' is being imported.
* @param {string} importSource - path of the import
* @param {Set.<string>} importNames - Set of import names that are being imported
* @param {string} importSource path of the import
* @param {Set.<string>} importNames Set of import names that are being imported
* @returns {boolean} whether the path is restricted
* @private
*/
@@ -198,8 +198,8 @@ module.exports = {
/**
* Check if the given importNames are restricted given a list of restrictedImportNames.
* @param {Set.<string>} importNames - Set of import names that are being imported
* @param {string[]} restrictedImportNames - array of import names that are restricted for this import
* @param {Set.<string>} importNames Set of import names that are being imported
* @param {string[]} restrictedImportNames array of import names that are restricted for this import
* @returns {boolean} whether the objectName is restricted
* @private
*/
@@ -211,8 +211,8 @@ module.exports = {
/**
* Check if the given importSource is a restricted path.
* @param {string} importSource - path of the import
* @param {Set.<string>} importNames - Set of import names that are being imported
* @param {string} importSource path of the import
* @param {Set.<string>} importNames Set of import names that are being imported
* @returns {boolean} whether the variable is a restricted path or not
* @private
*/
@@ -232,7 +232,7 @@ module.exports = {
/**
* Check if the given importSource is restricted by a pattern.
* @param {string} importSource - path of the import
* @param {string} importSource path of the import
* @returns {boolean} whether the variable is a restricted pattern or not
* @private
*/
+12 -13
View File
@@ -20,9 +20,8 @@ const SPACES = /\s+/gu;
/**
* Checks whether the property of 2 given member expression nodes are the same
* property or not.
*
* @param {ASTNode} left - A member expression node to check.
* @param {ASTNode} right - Another member expression node to check.
* @param {ASTNode} left A member expression node to check.
* @param {ASTNode} right Another member expression node to check.
* @returns {boolean} `true` if the member expressions have the same property.
*/
function isSameProperty(left, right) {
@@ -43,9 +42,8 @@ function isSameProperty(left, right) {
/**
* Checks whether 2 given member expression nodes are the reference to the same
* property or not.
*
* @param {ASTNode} left - A member expression node to check.
* @param {ASTNode} right - Another member expression node to check.
* @param {ASTNode} left A member expression node to check.
* @param {ASTNode} right Another member expression node to check.
* @returns {boolean} `true` if the member expressions are the reference to the
* same property or not.
*/
@@ -63,18 +61,20 @@ function isSameMember(left, right) {
if (lobj.type === "MemberExpression") {
return isSameMember(lobj, robj);
}
if (lobj.type === "ThisExpression") {
return true;
}
return lobj.type === "Identifier" && lobj.name === robj.name;
}
/**
* Traverses 2 Pattern nodes in parallel, then reports self-assignments.
*
* @param {ASTNode|null} left - A left node to traverse. This is a Pattern or
* @param {ASTNode|null} left A left node to traverse. This is a Pattern or
* a Property.
* @param {ASTNode|null} right - A right node to traverse. This is a Pattern or
* @param {ASTNode|null} right A right node to traverse. This is a Pattern or
* a Property.
* @param {boolean} props - The flag to check member expressions as well.
* @param {Function} report - A callback function to report.
* @param {boolean} props The flag to check member expressions as well.
* @param {Function} report A callback function to report.
* @returns {void}
*/
function eachSelfAssignment(left, right, props, report) {
@@ -205,8 +205,7 @@ module.exports = {
/**
* Reports a given node as self assignments.
*
* @param {ASTNode} node - A node to report. This is an Identifier node.
* @param {ASTNode} node A node to report. This is an Identifier node.
* @returns {void}
*/
function report(node) {
+3 -3
View File
@@ -54,7 +54,7 @@ module.exports = {
/**
* Determines whether a node is required by the grammar to be wrapped in
* parens, e.g. the test of an if statement.
* @param {ASTNode} node - The AST node
* @param {ASTNode} node The AST node
* @returns {boolean} True if parens around node belong to parent node.
*/
function requiresExtraParens(node) {
@@ -64,7 +64,7 @@ module.exports = {
/**
* Check if a node is wrapped in parens.
* @param {ASTNode} node - The AST node
* @param {ASTNode} node The AST node
* @returns {boolean} True if the node has a paren on each side.
*/
function isParenthesised(node) {
@@ -73,7 +73,7 @@ module.exports = {
/**
* Check if a node is wrapped in two levels of parens.
* @param {ASTNode} node - The AST node
* @param {ASTNode} node The AST node
* @returns {boolean} True if two parens surround the node on each side.
*/
function isParenthesisedTwice(node) {
+1 -4
View File
@@ -54,7 +54,6 @@ module.exports = {
/**
* Check if variable name is allowed.
*
* @param {ASTNode} variable The variable to check.
* @returns {boolean} Whether or not the variable name is allowed.
*/
@@ -67,7 +66,6 @@ module.exports = {
*
* ClassDeclaration creates two variables of its name into its outer scope and its class scope.
* So we should ignore the variable in the class scope.
*
* @param {Object} variable The variable to check.
* @returns {boolean} Whether or not the variable of the class name in the class scope of ClassDeclaration.
*/
@@ -82,7 +80,6 @@ module.exports = {
*
* To avoid reporting at declarations such as `var a = function a() {};`.
* But it should report `var a = function(a) {};` or `var a = function() { function a() {} };`.
*
* @param {Object} variable The variable to check.
* @param {Object} scopeVar The scope variable to look for.
* @returns {boolean} Whether or not the variable is inside initializer of scopeVar.
@@ -139,7 +136,7 @@ module.exports = {
/**
* Checks the current context for shadowed variables.
* @param {Scope} scope - Fixme
* @param {Scope} scope Fixme
* @returns {void}
*/
function checkForShadows(scope) {
+8 -2
View File
@@ -55,8 +55,14 @@ module.exports = {
context.report({
node,
loc: {
line: index + 1,
column: match.index
start: {
line: index + 1,
column: match.index
},
end: {
line: index + 1,
column: match.index + match[0].length
}
},
message: "Unexpected tab character."
});
Loaded 100 of 258 files, more files were not shown because too many files have changed in this diff. Show more