Skip to content

Commit

Permalink
fix: Avoid dirname for built-in configs.
Browse files Browse the repository at this point in the history
Load eslint:recommended and eslint:all configs via import instead file paths.

Fixes: eslint#15575
  • Loading branch information
zddai committed Feb 16, 2022
2 parents ce64343 + 3fc9196 commit 2dff129
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile.js
Expand Up @@ -73,7 +73,7 @@ const NODE = "node ", // intentional extra space
JSON_FILES = find("conf/").filter(fileType("json")),
MARKDOWNLINT_IGNORED_FILES = fs.readFileSync(path.join(__dirname, ".markdownlintignore"), "utf-8").split("\n"),
MARKDOWN_FILES_ARRAY = find("docs/").concat(ls(".")).filter(fileType("md")).filter(file => !MARKDOWNLINT_IGNORED_FILES.includes(file)),
TEST_FILES = "\"tests/{bin,lib,tools}/**/*.js\"",
TEST_FILES = "\"tests/{bin,conf,lib,tools}/**/*.js\"",
PERF_ESLINTRC = path.join(PERF_TMP_DIR, "eslintrc.yml"),
PERF_MULTIFILES_TARGET_DIR = path.join(PERF_TMP_DIR, "eslint"),
PERF_MULTIFILES_TARGETS = `"${PERF_MULTIFILES_TARGET_DIR + path.sep}{lib,tests${path.sep}lib}${path.sep}**${path.sep}*.js"`,
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -291,10 +291,10 @@ The following companies, organizations, and individuals support ESLint's ongoing
<!-- NOTE: This section is autogenerated. Do not manually edit.-->
<!--sponsorsstart-->
<h3>Platinum Sponsors</h3>
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a> <a href="https://flux.industries"><img src="https://avatars.githubusercontent.com/u/88303769?u=1af1d13b48676ab5918770999361829fc90847c4&v=4" alt="Flux Industries" height="undefined"></a></p><h3>Gold Sponsors</h3>
<p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" 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://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" 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/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.practiceignition.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" height="32"></a></p>
<p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" 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/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.ignitionapp.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" height="32"></a></p>
<!--sponsorsend-->

## <a name="technology-sponsors"></a>Technology Sponsors
Expand Down
7 changes: 3 additions & 4 deletions lib/cli-engine/cli-engine.js
Expand Up @@ -19,8 +19,7 @@ const fs = require("fs");
const path = require("path");
const defaultOptions = require("../../conf/default-cli-options");
const pkg = require("../../package.json");
const eslintRecommendedConfig = require("../../conf/eslint-recommended.js");
const eslintAllConfig = require("../../conf/eslint-all.js");


const {
Legacy: {
Expand Down Expand Up @@ -617,8 +616,8 @@ class CLIEngine {
useEslintrc: options.useEslintrc,
builtInRules,
loadRules,
eslintRecommendedConfig,
eslintAllConfig
getEslintRecommendedConfig: () => require("../../conf/eslint-recommended.js"),
getEslintAllConfig: () => require("../../conf/eslint-all.js")
});
const fileEnumerator = new FileEnumerator({
configArrayFactory,
Expand Down
6 changes: 2 additions & 4 deletions lib/cli-engine/file-enumerator.js
Expand Up @@ -40,8 +40,6 @@ const getGlobParent = require("glob-parent");
const isGlob = require("is-glob");
const escapeRegExp = require("escape-string-regexp");
const { Minimatch } = require("minimatch");
const eslintRecommendedConfig = require("../../conf/eslint-recommended.js");
const eslintAllConfig = require("../../conf/eslint-all.js");

const {
Legacy: {
Expand Down Expand Up @@ -217,8 +215,8 @@ class FileEnumerator {
cwd = process.cwd(),
configArrayFactory = new CascadingConfigArrayFactory({
cwd,
eslintRecommendedConfig,
eslintAllConfig
getEslintRecommendedConfig: () => require("../../conf/eslint-recommended.js"),
getEslintAllConfig: () => require("../../conf/eslint-all.js")
}),
extensions = null,
globInputPaths = true,
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/camelcase.js
Expand Up @@ -146,7 +146,7 @@ module.exports = {

/**
* Checks if a given binding identifier uses the original name as-is.
* - If it's in object destructuring, the original name is its property name.
* - If it's in object destructuring or object expression, the original name is its property name.
* - If it's in import declaration, the original name is its exported name.
* @param {ASTNode} node The `Identifier` node to check.
* @returns {boolean} `true` if the identifier uses the original name as-is.
Expand All @@ -161,7 +161,7 @@ module.exports = {
switch (parent.type) {
case "Property":
return (
parent.parent.type === "ObjectPattern" &&
(parent.parent.type === "ObjectPattern" || parent.parent.type === "ObjectExpression") &&
parent.value === valueNode &&
!parent.computed &&
parent.key.type === "Identifier" &&
Expand Down
101 changes: 101 additions & 0 deletions tests/lib/rules/camelcase.js
Expand Up @@ -407,6 +407,35 @@ ruleTester.run("camelcase", rule, {
code: "class C { snake_case; #snake_case; #snake_case2() {} }",
options: [{ properties: "never" }],
parserOptions: { ecmaVersion: 2022 }
},

// Combinations of `properties` and `ignoreDestructring`
{
code: `
const { some_property } = obj;
const bar = { some_property };
obj.some_property = 10;
const xyz = { some_property: obj.some_property };
const foo = ({ some_property }) => {
console.log(some_property)
};
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 }
},

// https://github.com/eslint/eslint/issues/15572
{
code: `
const { some_property } = obj;
doSomething({ some_property });
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 }
}
],
invalid: [
Expand Down Expand Up @@ -1416,6 +1445,78 @@ ruleTester.run("camelcase", rule, {
options: [{ properties: "always" }],
parserOptions: { ecmaVersion: 2022 },
errors: [{ messageId: "notCamelCasePrivate", data: { name: "snake_case" } }]
},

// Combinations of `properties` and `ignoreDestructring`
{
code: `
const { some_property } = obj;
doSomething({ some_property });
`,
options: [{ properties: "always", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
messageId: "notCamelCase",
data: { name: "some_property" },
line: 3,
column: 27
}
]
},
{
code: `
const { some_property } = obj;
doSomething({ some_property });
doSomething({ [some_property]: "bar" });
`,
options: [{ properties: "never", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
messageId: "notCamelCase",
data: { name: "some_property" },
line: 4,
column: 28
}
]
},
{
code: `
const { some_property } = obj;
const bar = { some_property };
obj.some_property = 10;
const xyz = { some_property: obj.some_property };
const foo = ({ some_property }) => {
console.log(some_property)
};
`,
options: [{ properties: "always", ignoreDestructuring: true }],
parserOptions: { ecmaVersion: 2022 },
errors: [
{
messageId: "notCamelCase",
data: { name: "some_property" },
line: 4,
column: 27
},
{
messageId: "notCamelCase",
data: { name: "some_property" },
line: 6,
column: 17
},
{
messageId: "notCamelCase",
data: { name: "some_property" },
line: 8,
column: 27
}
]
}
]
});

0 comments on commit 2dff129

Please sign in to comment.