Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09675e1

Browse files
authored
fix:--no-ignore should not apply to non-global ignores (#18334)
Fixes#18261
1 parent9048e21 commit09675e1

File tree

3 files changed

+75
-4
lines changed

3 files changed

+75
-4
lines changed

‎lib/config/flat-config-array.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const { defaultConfig } = require("./default-config");
1818
// Helpers
1919
//-----------------------------------------------------------------------------
2020

21+
/**
22+
* Fields that are considered metadata and not part of the config object.
23+
*/
24+
constMETA_FIELDS=newSet(["name"]);
25+
2126
construleValidator=newRuleValidator();
2227

2328
/**
@@ -135,15 +140,15 @@ class FlatConfigArray extends ConfigArray {
135140
[ConfigArraySymbol.preprocessConfig](config){
136141

137142
/*
138-
* If`shouldIgnore` is false, we remove any ignore patterns specified
139-
*in the config so long as it's not a default config and it doesn't
140-
*have a `files` entry.
143+
* Ifa config object has `ignores` and no other non-meta fields, then it's an object
144+
*for global ignores. If `shouldIgnore` is false, that object shouldn't apply,
145+
*so we'll remove its `ignores`.
141146
*/
142147
if(
143148
!this.shouldIgnore&&
144149
!this[originalBaseConfig].includes(config)&&
145150
config.ignores&&
146-
!config.files
151+
Object.keys(config).filter(key=>!META_FIELDS.has(key)).length===1
147152
){
148153
/* eslint-disable-next-line no-unused-vars -- need to strip off other keys */
149154
const{ ignores, ...otherKeys}=config;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
consteslintConfig=require("./eslint.config.js");
2+
3+
module.exports=[
4+
eslintConfig,
5+
{
6+
name:"Global ignores",
7+
ignores:["**/*.json","**/*.js"]
8+
}
9+
];

‎tests/lib/eslint/eslint.js‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,16 @@ describe("ESLint", () => {
16301630
},/Allfilesmatchedby'tests\/fixtures\/cli-engine\/'areignored\./u);
16311631
});
16321632

1633+
it("should throw an error when all given files are ignored by a config object that has `name`",async()=>{
1634+
eslint=newESLint({
1635+
overrideConfigFile:getFixturePath("eslint.config-with-ignores3.js")
1636+
});
1637+
1638+
awaitassert.rejects(async()=>{
1639+
awaiteslint.lintFiles(["tests/fixtures/cli-engine/"]);
1640+
},/Allfilesmatchedby'tests\/fixtures\/cli-engine\/'areignored\./u);
1641+
});
1642+
16331643
it("should throw an error when all given files are ignored even with a `./` prefix",async()=>{
16341644
eslint=newESLint({
16351645
overrideConfigFile:getFixturePath("eslint.config-with-ignores.js")
@@ -1775,6 +1785,29 @@ describe("ESLint", () => {
17751785
assert.strictEqual(results[0].suppressedMessages.length,0);
17761786
});
17771787

1788+
it("should return two messages when given a file in excluded files list by a config object that has `name` while ignore is off",async()=>{
1789+
eslint=newESLint({
1790+
cwd:getFixturePath(),
1791+
ignore:false,
1792+
overrideConfigFile:getFixturePath("eslint.config-with-ignores3.js"),
1793+
overrideConfig:{
1794+
rules:{
1795+
"no-undef":2
1796+
}
1797+
}
1798+
});
1799+
constfilePath=fs.realpathSync(getFixturePath("undef.js"));
1800+
constresults=awaiteslint.lintFiles([filePath]);
1801+
1802+
assert.strictEqual(results.length,1);
1803+
assert.strictEqual(results[0].filePath,filePath);
1804+
assert.strictEqual(results[0].messages[0].ruleId,"no-undef");
1805+
assert.strictEqual(results[0].messages[0].severity,2);
1806+
assert.strictEqual(results[0].messages[1].ruleId,"no-undef");
1807+
assert.strictEqual(results[0].messages[1].severity,2);
1808+
assert.strictEqual(results[0].suppressedMessages.length,0);
1809+
});
1810+
17781811
// https://github.com/eslint/eslint/issues/16300
17791812
it("should process ignore patterns relative to basePath not cwd",async()=>{
17801813
eslint=newESLint({
@@ -5698,6 +5731,30 @@ describe("ESLint", () => {
56985731
assert.strictEqual(warnResult.messages[0].ruleId,"no-unused-vars");
56995732
assert.strictEqual(warnResult.messages[0].severity,1);
57005733
});
5734+
5735+
// https://github.com/eslint/eslint/issues/18261
5736+
it("should apply to all files except for 'error.js' even with `ignore: false` option",async()=>{
5737+
constengine=newESLint({
5738+
cwd,
5739+
ignore:false
5740+
});
5741+
5742+
constresults=awaitengine.lintFiles("{error,warn}.js");
5743+
5744+
assert.strictEqual(results.length,2);
5745+
5746+
const[errorResult,warnResult]=results;
5747+
5748+
assert.strictEqual(errorResult.filePath,path.join(getPath(),"error.js"));
5749+
assert.strictEqual(errorResult.messages.length,1);
5750+
assert.strictEqual(errorResult.messages[0].ruleId,"no-unused-vars");
5751+
assert.strictEqual(errorResult.messages[0].severity,2);
5752+
5753+
assert.strictEqual(warnResult.filePath,path.join(getPath(),"warn.js"));
5754+
assert.strictEqual(warnResult.messages.length,1);
5755+
assert.strictEqual(warnResult.messages[0].ruleId,"no-unused-vars");
5756+
assert.strictEqual(warnResult.messages[0].severity,1);
5757+
});
57015758
});
57025759

57035760
describe("config with ignores: ['**/*.json']",()=>{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp