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

Relative 'extends' no longer error out in the XO VS Code extension, nor if running XO from a different folder #686

Merged
merged 6 commits into from
Oct 4, 2022
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
2 changes: 1 addition & 1 deletion lib/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ const buildExtendsConfig = options => config => {
if (options.extends && options.extends.length > 0) {
const configs = options.extends.map(name => {
// Don't do anything if it's a filepath
if (existsSync(name)) {
if (existsSync(path.resolve(options.cwd || process.cwd(), name))) {
return name;
}

Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/config-files/extends-relative/.xo-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../extends.js"
}
5 changes: 5 additions & 0 deletions test/fixtures/config-files/extends-relative/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const object = {
a: 1
};

console.log(object.a);
17 changes: 17 additions & 0 deletions test/lint-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,20 @@ test(configType, {type: '.xo-config.js', dir: 'xo-config_js'});
test(configType, {type: '.xo-config.cjs', dir: 'xo-config_cjs'});
test(configType, {type: '.xo-config.json', dir: 'xo-config_json'});
test(configType, {type: '.xo-config', dir: 'xo-config'});

test('load config file with relative extends from different cwd', async t => {
const directory = 'extends-relative';

const {results, rulesMeta} = await xo.lintFiles('**/*', {
cwd: path.resolve('fixtures', 'config-files', directory),
});

t.true(
hasRule(
results,
path.resolve('fixtures', 'config-files', directory, 'file.js'),
'comma-dangle',
rulesMeta,
),
);
});
2 changes: 1 addition & 1 deletion test/lint-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ test('extends `react` support with `prettier` option', async t => {

test('regression test for #71', async t => {
const {results} = await xo.lintText('const foo = { key: \'value\' };\nconsole.log(foo);\n', {
extends: path.join(__dirname, 'fixtures/extends.js'),
extends: './fixtures/extends.js',
});
t.is(results[0].errorCount, 0);
});
Expand Down
4 changes: 3 additions & 1 deletion test/options-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,14 @@ test('buildConfig: extends', t => {
extends: [
'plugin:foo/bar',
'eslint-config-prettier',
'./fixtures/config-files/xo_config_js/xo.config.js',
],
});

t.deepEqual(config.baseConfig.extends.slice(-2), [
t.deepEqual(config.baseConfig.extends.slice(-3), [
'plugin:foo/bar',
path.resolve('../node_modules/eslint-config-prettier/index.js'),
'./fixtures/config-files/xo_config_js/xo.config.js',
]);
});

Expand Down