Skip to content

Commit

Permalink
Correctly use ignores config, Lint xo with xo (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Aug 7, 2021
1 parent e2e715d commit 48baacc
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 16 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
getIgnores,
mergeWithFileConfig,
buildConfig,
mergeOptions,
} from './lib/options-manager.js';

/** Merge multiple reports into a single report */
Expand Down Expand Up @@ -152,7 +151,7 @@ const lintFiles = async (patterns, inputOptions = {}) => {
inputOptions = normalizeOptions(inputOptions);
inputOptions.cwd = path.resolve(inputOptions.cwd || process.cwd());

const files = await globFiles(patterns, mergeOptions(inputOptions));
const files = await globFiles(patterns, mergeWithFileConfig(inputOptions).options);

const reports = await pMap(
files,
Expand Down
7 changes: 4 additions & 3 deletions lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,13 @@ const gatherImportResolvers = options => {
};

export {
findApplicableOverrides,
mergeWithPrettierConfig,
normalizeOptions,
getIgnores,
mergeWithFileConfig,
buildConfig,

// For tests
applyOverrides,
mergeOptions,
findApplicableOverrides,
mergeWithPrettierConfig,
};
17 changes: 6 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"node": ">=12.20"
},
"scripts": {
"test": "eslint --quiet . --ext .js,.cjs && nyc ava"
"test": "node cli.js && nyc ava"
},
"files": [
"config",
Expand Down Expand Up @@ -106,18 +106,13 @@
"temp-write": "^5.0.0",
"webpack": "^5.48.0"
},
"eslintConfig": {
"extends": [
"eslint-config-xo",
"./config/plugins.cjs",
"./config/overrides.cjs"
"xo": {
"ignores": [
"test/fixtures",
"test/temp",
"coverage"
]
},
"eslintIgnore": [
"test/fixtures",
"test/temp",
"coverage"
],
"ava": {
"files": [
"!test/temp"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/nested-ignores/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('semicolon')
1 change: 1 addition & 0 deletions test/fixtures/nested-ignores/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('semicolon')
1 change: 1 addition & 0 deletions test/fixtures/nested-ignores/child/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('semicolon')
1 change: 1 addition & 0 deletions test/fixtures/nested-ignores/child/b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('semicolon')
8 changes: 8 additions & 0 deletions test/fixtures/nested-ignores/child/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"xo": {
"ignores": [
"b.js",
"**/b.js"
]
}
}
8 changes: 8 additions & 0 deletions test/fixtures/nested-ignores/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"xo": {
"ignores": [
"a.js",
"**/a.js"
]
}
}
40 changes: 40 additions & 0 deletions test/ignores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import path from 'node:path';
import test from 'ava';
import createEsmUtils from 'esm-utils';
import {globby} from 'globby';
import xo from '../index.js';

const {__dirname} = createEsmUtils(import.meta);

test('Should pickup "ignores" config', async t => {
const cwd = path.join(__dirname, 'fixtures/nested-ignores');

t.deepEqual(
await globby(['**/*.js'], {cwd}),
['a.js', 'b.js', 'child/a.js', 'child/b.js'],
'Should has 4 js files.',
);

// Should not match
// `a.js` (ignored by config in current directory)
// `child/a.js` (ignored by config in current directory)
// `child/b.js` (ignored by config in child directory)
const result = await xo.lintFiles('.', {cwd});
const files = result.results.map(({filePath}) => filePath);
t.deepEqual(files, [path.join(cwd, 'b.js')], 'Should only report on `b.js`.');
});

test('Should ignore "ignores" config in parent', async t => {
const cwd = path.join(__dirname, 'fixtures/nested-ignores/child');

t.deepEqual(
await globby(['**/*.js'], {cwd}),
['a.js', 'b.js'],
'Should has 2 js files.',
);

// Should only match `a.js` even it's ignored in parent
const result = await xo.lintFiles('.', {cwd});
const files = result.results.map(({filePath}) => filePath);
t.deepEqual(files, [path.join(cwd, 'a.js')], 'Should only report on `a.js`.');
});

0 comments on commit 48baacc

Please sign in to comment.