Skip to content

Commit

Permalink
fix: do not check binary files and add Ada dictionary (#1011)
Browse files Browse the repository at this point in the history
* fix: add Ada dictionary
* fix: do not load binary files when spell checking.
* fix: add Ada to known file types.
* ci: Add integration test for Ada repo
* fix: Issue with glob root resolution.
* ci: Update Azure integration test
  • Loading branch information
Jason3S committed Feb 26, 2021
1 parent c748f09 commit af04ead
Show file tree
Hide file tree
Showing 15 changed files with 2,933 additions and 106 deletions.
1 change: 1 addition & 0 deletions .github/workflows/integration-test.yml
Expand Up @@ -35,6 +35,7 @@ jobs:
- wireapp/wire-desktop wireapp/wire-webapp
- django/django
- TheAlgorithms/Python
- AdaDoom3/AdaDoom3

steps:
- uses: actions/checkout@v2
Expand Down
14 changes: 11 additions & 3 deletions integration-tests/config/config.json
Expand Up @@ -158,11 +158,11 @@
{
"path": "Azure/azure-rest-api-specs",
"url": "https://github.com/Azure/azure-rest-api-specs.git",
"commit": "80f368e639e71088d201d235a9174a5d434c6ff6",
"args": [
"--config=cSpell.json",
"**/*.{md,ts,js}"
]
],
"commit": "a06d912bc912010bdc0aa5d1d3c4b28ee1d89905"
},
{
"path": "pycontribs/jira",
Expand Down Expand Up @@ -221,6 +221,14 @@
"**/*.*"
],
"commit": "1171f431bbf6b1d84556fb19de54626f59deb0d6"
},
{
"path": "AdaDoom3/AdaDoom3",
"url": "https://github.com/AdaDoom3/AdaDoom3.git",
"args": [
"**/*.*"
],
"commit": "06416b73f27740b29581df0acbc6dd1ced9a8d7c"
}
]
}
}
16 changes: 16 additions & 0 deletions integration-tests/repositories/cspell.yaml
@@ -1,2 +1,18 @@
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json"
version: 0.2
id: integration-test-default
words:
- octokit

ignorePaths:
- "*.ktx"

overrides:
- filename: "temp/TheAlgorithms/Python/**/*.py"
languageSettings:
- languageId: python
allowCompoundWords: true
- filename: "temp/AdaDoom3/AdaDoom3/**/*.py"
languageSettings:
- languageId: python
allowCompoundWords: false
2,725 changes: 2,725 additions & 0 deletions integration-tests/snapshots/AdaDoom3/AdaDoom3/snapshot.txt

Large diffs are not rendered by default.

175 changes: 101 additions & 74 deletions integration-tests/snapshots/Azure/azure-rest-api-specs/snapshot.txt

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/cspell-bundled-dicts/cspell-default.json
@@ -1,6 +1,7 @@
{
"version": "0.1",
"name": "cspell default json",
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/master/cspell.schema.json",
"version": "0.2",
"name": "cspell default settings",
"id": "cspell-default",
"language": "en",
"description": "Default cspell configuration.",
Expand Down Expand Up @@ -78,6 +79,7 @@
}
],
"import": [
"@cspell/dict-ada/cspell-ext.json",
"@cspell/dict-aws/cspell-ext.json",
"@cspell/dict-bash/cspell-ext.json",
"@cspell/dict-companies/cspell-ext.json",
Expand Down
11 changes: 8 additions & 3 deletions packages/cspell-bundled-dicts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/cspell-bundled-dicts/package.json
Expand Up @@ -31,9 +31,10 @@
},
"homepage": "https://github.com/streetsidesoftware/cspell#readme",
"dependencies": {
"@cspell/dict-ada": "^1.1.1",
"@cspell/dict-aws": "^1.0.13",
"@cspell/dict-bash": "^1.0.11",
"@cspell/dict-companies": "^1.0.35",
"@cspell/dict-companies": "^1.0.36",
"@cspell/dict-cpp": "^1.1.37",
"@cspell/dict-cryptocurrencies": "^1.0.10",
"@cspell/dict-csharp": "^1.0.10",
Expand Down
10 changes: 8 additions & 2 deletions packages/cspell-lib/src/LanguageIds.ts
Expand Up @@ -22,6 +22,8 @@ export type LanguageExtensionDefinitions = LanguageExtensionDefinition[];
export type ExtensionToLanguageIdMap = Map<string, Set<string>>;

export const languageExtensionDefinitions: LanguageExtensionDefinitions = [
{ id: 'ada', extensions: ['.adb', '.ads'] },
{ id: 'apiblueprint', extensions: ['.apib', '.apiblueprint'] },
{ id: 'asciidoc', extensions: ['.adoc', '.asc', '.asciidoc'] },
{ id: 'bat', extensions: ['.bat', '.cmd'] },
{ id: 'clojure', extensions: ['.clj', '.cljs', '.cljx', '.clojure', '.edn'] },
Expand Down Expand Up @@ -56,6 +58,7 @@ export const languageExtensionDefinitions: LanguageExtensionDefinitions = [
extensions: ['.json', '.jsonc', '.bowerrc', '.jshintrc', '.jscsrc', '.eslintrc', '.babelrc', '.webmanifest'],
},
{ id: 'less', extensions: ['.less'] },
{ id: 'literate haskell', extensions: ['.lhs'] },
{ id: 'lua', extensions: ['.lua'] },
{ id: 'makefile', extensions: ['.mk'] },
{ id: 'markdown', extensions: ['.md', '.mdown', '.markdown', '.markdn'] },
Expand Down Expand Up @@ -168,13 +171,16 @@ export const languageExtensionDefinitions: LanguageExtensionDefinitions = [
{ id: 'yaml', extensions: ['.eyaml', '.eyml', '.yaml', '.yml'] },
{ id: 'latex', extensions: ['.tex'] },
{ id: 'map', extensions: ['.map'] },

//
// Special file types used to prevent spell checking.
//
{ id: 'image', extensions: ['.jpg', '.png', '.jpeg', '.tiff', '.bmp', '.gif'] },
// cspell:ignore woff
{
id: 'binary',
extensions: ['.gz', '.exe', '.dll', '.lib', '.obj', '.o', '.tff', '.woff', '.woff2', '.eot', '.ico'],
extensions: ['.gz', '.exe', '.dll', '.lib', '.obj', '.o', '.tff', '.woff', '.woff2', '.eot', '.ico', '.cur'],
},
{ id: 'apiblueprint', extensions: ['.apib', '.apiblueprint'] },
];

export const languageIds: string[] = languageExtensionDefinitions.map(({ id }) => id);
Expand Down
3 changes: 2 additions & 1 deletion packages/cspell-lib/src/Settings/CSpellSettingsServer.ts
Expand Up @@ -614,11 +614,12 @@ export function extractImportErrors(settings: CSpellSettings): ImportFileRefWith
function resolveGlobRoot(settings: CSpellSettings, pathToSettingsFile: string): string {
const settingsFileDir = path.dirname(pathToSettingsFile);
const envGlobRoot = process.env[ENV_CSPELL_GLOB_ROOT];
const cwd = envGlobRoot || process.cwd();
const defaultGlobRoot = envGlobRoot ?? '${cwd}';
const rawRoot =
settings.globRoot ??
(settings.version === '0.1' || (envGlobRoot && !settings.version) ? defaultGlobRoot : settingsFileDir);
const globRoot = path.resolve(settingsFileDir, rawRoot.replace('${cwd}', process.cwd()));
const globRoot = path.resolve(settingsFileDir, rawRoot.replace('${cwd}', cwd));
return globRoot;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cspell-lib/src/Settings/DefaultSettings.test.ts
Expand Up @@ -8,6 +8,6 @@ describe('Validate Default Settings', () => {

test('tests the default setting file is loaded', () => {
const defaultSetting = DefaultSettings.getDefaultSettings();
expect(defaultSetting.name).toBe('cspell default json');
expect(defaultSetting.name).toBe('cspell default settings');
});
});
2 changes: 2 additions & 0 deletions packages/cspell-lib/src/Settings/DefaultSettings.ts
Expand Up @@ -75,6 +75,7 @@ export const _defaultSettings: CSpellSettingsWithSourceTrace = {
name: 'Static Defaults',
enabled: true,
enabledLanguageIds: [
'ada',
'csharp',
'go',
'javascript',
Expand All @@ -88,6 +89,7 @@ export const _defaultSettings: CSpellSettingsWithSourceTrace = {
'text',
'typescript',
'typescriptreact',
'haskell',
'html',
'css',
'less',
Expand Down
45 changes: 27 additions & 18 deletions packages/cspell-lib/src/spellCheckFile.test.ts
Expand Up @@ -122,8 +122,15 @@ describe('Validate Spell Checking Documents', () => {
return URI.file(s(file)).toString();
}

function d(uri: string, text?: string): Document {
return text === undefined ? { uri } : { uri, text };
function d(uri: string | Document, text?: string, languageId?: string): Document {
const doc: Document = typeof uri === 'string' ? { uri } : { ...uri };
if (text) {
doc.text = text;
}
if (languageId) {
doc.languageId = languageId;
}
return doc;
}

type ArrayType<T> = T extends (infer R)[] ? R : never;
Expand All @@ -136,22 +143,24 @@ describe('Validate Spell Checking Documents', () => {

// cspell:ignore texxt
test.each`
uri | text | settings | options | expected
${f('src/not_found.c')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: [errNoEnt('src/not_found.c')] }}
${f('src/sample.c')} | ${''} | ${{}} | ${{}} | ${{ checked: true, issues: [], localConfigFilepath: s('.cspell.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ noConfigSearch: true }} | ${{ checked: true, localConfigFilepath: undefined, errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{}} | ${{ checked: true, localConfigFilepath: undefined, errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ configFile: s('../cspell.config.json') }} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{ configFile: s('../cspell.config.json') }} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{ noConfigSearch: false }} | ${{ checked: true, localConfigFilepath: s('.cspell.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{}} | ${{ document: oc(d(f('src/sample.c'))), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ configFile: s('../cSpell.json') }} | ${{ checked: false, localConfigFilepath: s('../cSpell.json'), errors: [eFailed(s('../cSpell.json'))] }}
${f('src/not_found.c')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: [errNoEnt('src/not_found.c')] }}
${f(__filename)} | ${''} | ${{}} | ${{}} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${'stdin:///'} | ${'some text'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: true, issues: [], localConfigFilepath: undefined, errors: undefined }}
${'stdin:///'} | ${'some text'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ document: oc(d('stdin:///')) }}
${'stdin:///'} | ${'some texxt'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: true, issues: i('texxt'), localConfigFilepath: undefined, errors: undefined }}
${'stdin:///'} | ${''} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: false, issues: [], localConfigFilepath: undefined, errors: [err('Unsupported schema: "stdin", open "stdin:/"')] }}
uri | text | settings | options | expected
${f('src/not_found.c')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: [errNoEnt('src/not_found.c')] }}
${f('src/sample.c')} | ${''} | ${{}} | ${{}} | ${{ checked: true, issues: [], localConfigFilepath: s('.cspell.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ noConfigSearch: true }} | ${{ checked: true, localConfigFilepath: undefined, errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{}} | ${{ checked: true, localConfigFilepath: undefined, errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ configFile: s('../cspell.config.json') }} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{ configFile: s('../cspell.config.json') }} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{ noConfigSearch: true }} | ${{ noConfigSearch: false }} | ${{ checked: true, localConfigFilepath: s('.cspell.json'), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{}} | ${{ document: oc(d(f('src/sample.c'))), errors: undefined }}
${f('src/sample.c')} | ${''} | ${{}} | ${{ configFile: s('../cSpell.json') }} | ${{ checked: false, localConfigFilepath: s('../cSpell.json'), errors: [eFailed(s('../cSpell.json'))] }}
${f('src/not_found.c')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: [errNoEnt('src/not_found.c')] }}
${f(__filename)} | ${''} | ${{}} | ${{}} | ${{ checked: true, localConfigFilepath: s('../cspell.config.json'), errors: undefined }}
${'stdin:///'} | ${'some text'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: true, issues: [], localConfigFilepath: undefined, errors: undefined }}
${'stdin:///'} | ${'some text'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ document: oc(d('stdin:///')) }}
${'stdin:///'} | ${'some texxt'} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: true, issues: i('texxt'), localConfigFilepath: undefined, errors: undefined }}
${'stdin:///'} | ${''} | ${{ languageId: 'plaintext' }} | ${{}} | ${{ checked: false, issues: [], localConfigFilepath: undefined, errors: [err('Unsupported schema: "stdin", open "stdin:/"')] }}
${f('src/big_image.jpeg')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: undefined }}
${d(f('src/big_image.txt'), undefined, 'binary')} | ${''} | ${{}} | ${{}} | ${{ checked: false, errors: undefined }}
`(
'spellCheckFile $uri $settings $options',
async ({ uri, text, settings, options, expected }: TestSpellCheckFile) => {
Expand Down
24 changes: 24 additions & 0 deletions packages/cspell-lib/src/spellCheckFile.ts
Expand Up @@ -88,6 +88,17 @@ export async function spellCheckDocument(
options: SpellCheckFileOptions,
settings: CSpellUserSettings
): Promise<SpellCheckFileResult> {
if (isBinaryDoc(document)) {
return {
document,
options,
settingsUsed: settings,
localConfigFilepath: undefined,
issues: [],
checked: false,
errors: undefined,
};
}
try {
return spellCheckFullDocument(await resolveDocument(document), options, settings);
} catch (e) {
Expand Down Expand Up @@ -240,6 +251,19 @@ export function determineFinalDocumentSettings(
};
}

function isBinaryDoc(document: Document): boolean {
return isBinaryFile(URI.parse(document.uri).fsPath, document.languageId);
}

function isBinaryFile(filename: string, languageId?: string | string[]): boolean {
const ext = path.extname(filename);
languageId = languageId || [];
languageId = typeof languageId === 'string' ? languageId.split(',') : languageId;
languageId = languageId.map((a) => a.trim());
const languageIds = new Set(languageId.length ? languageId : getLanguagesForExt(ext));
return languageIds.has('binary') || languageIds.has('image');
}

export function fileToDocument(file: string): Document;
export function fileToDocument(file: string, text: string, languageId?: string, locale?: string): DocumentWithText;
export function fileToDocument(
Expand Down
2 changes: 1 addition & 1 deletion packages/cspell/src/lint.ts
Expand Up @@ -170,7 +170,7 @@ export function runLint(cfg: CSpellApplicationConfiguration): Promise<RunResult>
}

async function run(): Promise<RunResult> {
if (cfg.root) {
if (cfg.options.root) {
process.env[cspell.ENV_CSPELL_GLOB_ROOT] = cfg.root;
}

Expand Down

0 comments on commit af04ead

Please sign in to comment.