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

fix: support cspell.config.js and remove support for cspell.js #895

Merged
merged 4 commits into from
Jan 27, 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
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
".prettierignore",
"**/.gitignore",
"**/.vscode/**",
"**/{cspell.json,cSpell.json,.cspell.json}",
"**/{cspell.*,cSpell.*,.cspell.*,cspell.config.*}",
"**/*.snap",
"**/*.trie",
"**/coverage/**",
Expand Down
7 changes: 7 additions & 0 deletions packages/cspell-lib/samples/js-config/cspell.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

const cspell = {
description: 'cspell.config.js file in samples/js-config',
};

module.exports = cspell;
7 changes: 0 additions & 7 deletions packages/cspell-lib/samples/js-config/cspell.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const cspell = {
description: 'cspell.js file in samples/linked',
description: 'cspell.config.js file in samples/linked',
import: ['./cspell-imports.json'],
};

Expand Down
16 changes: 8 additions & 8 deletions packages/cspell-lib/src/Settings/CSpellSettingsServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('Validate search/load config files', () => {
dir | expectedConfig
${samplesSrc} | ${cfg(s('.cspell.json'))}
${s('bug-fixes/bug345.ts')} | ${cfg(s('bug-fixes/cspell.json'))}
${s('linked')} | ${cfg(s('linked/cspell.js'))}
${s('linked')} | ${cfg(s('linked/cspell.config.js'))}
${s('yaml-config')} | ${cfg(s('yaml-config/cspell.yaml'), { id: 'Yaml Example Config' })}
`('Search from $dir', async ({ dir, expectedConfig }: TestSearchFrom) => {
const searchResult = await searchForConfig(dir);
Expand All @@ -289,11 +289,11 @@ describe('Validate search/load config files', () => {
}

test.each`
file | expectedConfig
${samplesSrc} | ${cfg(importError(samplesSrc))}
${s('bug-fixes')} | ${cfg(importError(s('bug-fixes')))}
${s('linked/cspell.js')} | ${cfg(s('linked/cspell.js'))}
${s('js-config/cspell.js')} | ${cfg(s('js-config/cspell.js'))}
file | expectedConfig
${samplesSrc} | ${cfg(importError(samplesSrc))}
${s('bug-fixes')} | ${cfg(importError(s('bug-fixes')))}
${s('linked/cspell.config.js')} | ${cfg(s('linked/cspell.config.js'))}
${s('js-config/cspell.config.js')} | ${cfg(s('js-config/cspell.config.js'))}
`('Load from $file', async ({ file, expectedConfig }: TestLoadConfig) => {
const searchResult = await loadConfig(file);
expect(searchResult).toEqual(expectedConfig ? expect.objectContaining(expectedConfig) : undefined);
Expand All @@ -303,8 +303,8 @@ describe('Validate search/load config files', () => {
file | expectedConfig
${samplesSrc} | ${cfg(readError(samplesSrc))}
${s('bug-fixes')} | ${cfg(readError(s('bug-fixes')))}
${s('linked/cspell.js')} | ${cfg(s('linked/cspell.js'), { description: 'cspell.js file in samples/linked', import: ['./cspell-imports.json'] })}
${s('js-config/cspell.js')} | ${cfg(s('js-config/cspell.js'), { description: 'cspell.js file in samples/js-config' })}
${s('linked/cspell.config.js')} | ${cfg(s('linked/cspell.config.js'), { description: 'cspell.config.js file in samples/linked', import: ['./cspell-imports.json'] })}
${s('js-config/cspell.config.js')} | ${cfg(s('js-config/cspell.config.js'), { description: 'cspell.config.js file in samples/js-config' })}
${s('js-config/cspell-no-export.js')} | ${cfg(s('js-config/cspell-no-export.js'))}
${s('js-config/cspell-bad.js')} | ${cfg(readError(s('js-config/cspell-bad.js')))}
`('ReadRawSettings from $file', async ({ file, expectedConfig }: TestLoadConfig) => {
Expand Down
19 changes: 10 additions & 9 deletions packages/cspell-lib/src/Settings/CSpellSettingsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,21 @@ export const defaultFileName = 'cspell.json';

const cspellCosmiconfig = {
searchPlaces: [
'package.json',
'cspell.config.js',
'cspell.config.cjs',
'cspell.config.json',
'cspell.config.yaml',
'cspell.config.yml',
'cspell.yaml',
'cspell.yml',
'.cspell.json',
'cspell.json',
// Alternate locations
'.cSpell.json',
'cSpell.json',
'.cspell.json',
'.vscode/cspell.json',
'.vscode/cSpell.json',
'.vscode/.cspell.json',
'.cSpell.json',
'cspell.yaml',
'cspell.yml',
'cspell.js',
'cspell.cjs',
'.cspell.js',
'.cspell.cjs',
],
loaders: {
'.json': (_filename: string, content: string) => json.parse(content),
Expand Down