Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: refactoring for no-unsupported-features/*
- Loading branch information
1 parent
8f25248
commit fa25150
Showing
8 changed files
with
188 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* @author Toru Nagashima | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict" | ||
|
||
const { Range } = require("semver") //eslint-disable-line no-unused-vars | ||
const { ReferenceTracker } = require("eslint-utils") | ||
const getConfiguredNodeVersion = require("./get-configured-node-version") | ||
const getSemverRange = require("./get-semver-range") | ||
|
||
/** | ||
* Parses the options. | ||
* @param {RuleContext} context The rule context. | ||
* @returns {{version:Range,ignores:Set<string>}} Parsed value. | ||
*/ | ||
function parseOptions(context) { | ||
const raw = context.options[0] || {} | ||
const filePath = context.getFilename() | ||
const version = getConfiguredNodeVersion(raw.version, filePath) | ||
const ignores = new Set(raw.ignores || []) | ||
|
||
return Object.freeze({ version, ignores }) | ||
} | ||
|
||
/** | ||
* Verify the code to report unsupported APIs. | ||
* @param {RuleContext} context The rule context. | ||
* @param {{modules:object,globals:object}} trackMap The map for APIs to report. | ||
* @returns {void} | ||
*/ | ||
module.exports = function checkUnsupportedBuiltins(context, trackMap) { | ||
const options = parseOptions(context) | ||
const tracker = new ReferenceTracker(context.getScope(), { | ||
mode: "legacy", | ||
}) | ||
const references = [ | ||
...tracker.iterateCjsReferences(trackMap.modules || {}), | ||
...tracker.iterateEsmReferences(trackMap.modules || {}), | ||
...tracker.iterateGlobalReferences(trackMap.globals || {}), | ||
] | ||
|
||
for (const { node, path, info } of references) { | ||
const name = path.join(".") | ||
const supported = options.version.intersects( | ||
getSemverRange(`<${info.supported}`) | ||
) | ||
|
||
if (supported && !options.ignores.has(name)) { | ||
context.report({ | ||
node, | ||
messageId: "unsupported", | ||
data: { | ||
name, | ||
supported: info.supported, | ||
version: options.version.raw, | ||
}, | ||
}) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @author Toru Nagashima <https://github.com/mysticatea> | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict" | ||
|
||
const { Range } = require("semver") //eslint-disable-line no-unused-vars | ||
const getPackageJson = require("./get-package-json") | ||
const getSemverRange = require("./get-semver-range") | ||
|
||
/** | ||
* Get the `engines.node` field of package.json. | ||
* @param {string} filename The path to the current linting file. | ||
* @returns {Range|null} The range object of the `engines.node` field. | ||
*/ | ||
function getEnginesNode(filename) { | ||
const info = getPackageJson(filename) | ||
return getSemverRange(info && info.engines && info.engines.node) | ||
} | ||
|
||
/** | ||
* Gets version configuration. | ||
* | ||
* 1. Parse a given version then return it if it's valid. | ||
* 2. Look package.json up and parse `engines.node` then return it if it's valid. | ||
* 3. Return `>=6.0.0`. | ||
* | ||
* @param {string|undefined} version The version range text. | ||
* @param {string} filename The path to the current linting file. | ||
* This will be used to look package.json up if `version` is not a valid version range. | ||
* @returns {Range} The configured version range. | ||
*/ | ||
module.exports = function getConfiguredNodeVersion(version, filename) { | ||
return ( | ||
getSemverRange(version) || | ||
getEnginesNode(filename) || | ||
getSemverRange(">=6.0.0") | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.