Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly use ignores config, Lint xo with xo #584

Merged
merged 4 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.');
});