From 1c1e76a50bfb1a84bc41f712c7cd0fde1a85edc5 Mon Sep 17 00:00:00 2001 From: Jason Dent Date: Mon, 29 Aug 2022 16:59:04 +0200 Subject: [PATCH] fix: Make sure files are checked (#930) * fix: Make sure files are checked fix #318 --- action-src/cspell.json | 4 + .../src/__snapshots__/action.test.ts.snap | 510 +++++++++++++++++- action-src/src/action.test.ts | 25 +- action-src/src/action.ts | 10 +- action-src/src/spell.test.ts | 4 +- action-src/src/spell.ts | 1 - action/lib/action.js | 9 +- action/lib/spell.js | 1 - cspell.json | 1 + fixtures/cspell.json | 3 + 10 files changed, 530 insertions(+), 38 deletions(-) diff --git a/action-src/cspell.json b/action-src/cspell.json index 41de87b89..434bcd850 100644 --- a/action-src/cspell.json +++ b/action-src/cspell.json @@ -1,11 +1,15 @@ { "ignorePaths": [ "**/coverage/**", + "**/.git/*/**", + "**/.git/!{COMMIT_EDITMSG,EDITMSG}", "node_modules", "__recordings__", "__snapshots__" ], + "useGitignore": true, "ignoreWords": [ + "EDITMSG", "pollyjs" ] } diff --git a/action-src/src/__snapshots__/action.test.ts.snap b/action-src/src/__snapshots__/action.test.ts.snap index 25e00e056..1db092901 100644 --- a/action-src/src/__snapshots__/action.test.ts.snap +++ b/action-src/src/__snapshots__/action.test.ts.snap @@ -11,16 +11,16 @@ Array [ exports[`Validate Action check all **/*.md 1`] = `Array []`; -exports[`Validate Action check files with issues fixtures/sampleCode/** 1`] = ` +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "" 1`] = ` Array [ "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:19 Unknown word (Functon)", "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:27 Unknown word (countt)", ] `; -exports[`Validate Action check files with issues fixtures/sampleCode/** 2`] = `Array []`; +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "" 2`] = `Array []`; -exports[`Validate Action check files with issues fixtures/sampleCode/** 3`] = ` +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "" 3`] = ` Array [ Array [ "Pull Request @@ -35,7 +35,7 @@ Array [ ", ], Array [ - "Files checked: 2, Issues found: 2 in 1 files. + "Files checked: 4, Issues found: 2 in 1 files. ", ], Array [ @@ -51,7 +51,7 @@ Array [ ", ], Array [ - "::set-output name=number_of_files_checked::2 + "::set-output name=number_of_files_checked::4 ", ], Array [ @@ -83,32 +83,502 @@ Array [ ", ], Array [ - "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":2,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} ", ], ] `; -exports[`Validate Action check files with issues fixtures/sampleCode/** 4`] = ` +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "" 4`] = ` Array [ "Pull Request", "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon)", "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt)", - "Files checked: 2, Issues found: 2 in 1 files.", + "Files checked: 4, Issues found: 2 in 1 files.", "::set-output name=success::false", - "::set-output name=number_of_files_checked::2", + "::set-output name=number_of_files_checked::4", "::set-output name=number_of_issues::2", "::set-output name=number_of_files_with_issues::1", "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]", - "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":2,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", ] `; -exports[`Validate Action check files with issues fixtures/sampleCode/** 5`] = `Array []`; +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "explicit" 1`] = ` +Array [ + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:19 Unknown word (Functon)", + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:27 Unknown word (countt)", +] +`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "explicit" 2`] = `Array []`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "explicit" 3`] = ` +Array [ + Array [ + "Pull Request +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon) +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt) +", + ], + Array [ + "Files checked: 4, Issues found: 2 in 1 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::false +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::4 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::2 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::1 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} +", + ], +] +`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "explicit" 4`] = ` +Array [ + "Pull Request", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon)", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt)", + "Files checked: 4, Issues found: 2 in 1 files.", + "::set-output name=success::false", + "::set-output name=number_of_files_checked::4", + "::set-output name=number_of_issues::2", + "::set-output name=number_of_files_with_issues::1", + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]", + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", +] +`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "true" 1`] = ` +Array [ + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:19 Unknown word (Functon)", + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:27 Unknown word (countt)", +] +`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "true" 2`] = `Array []`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "true" 3`] = ` +Array [ + Array [ + "Pull Request +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon) +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt) +", + ], + Array [ + "Files checked: 6, Issues found: 2 in 1 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::false +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::6 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::2 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::1 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":6,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} +", + ], +] +`; + +exports[`Validate Action check files "" incremental: false pull_request_with_files.json, dot: "true" 4`] = ` +Array [ + "Pull Request", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon)", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt)", + "Files checked: 6, Issues found: 2 in 1 files.", + "::set-output name=success::false", + "::set-output name=number_of_files_checked::6", + "::set-output name=number_of_issues::2", + "::set-output name=number_of_files_with_issues::1", + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]", + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":6,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", +] +`; + +exports[`Validate Action check files "" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 1`] = ` +Array [ + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:19 Unknown word (Functon)", + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:27 Unknown word (countt)", +] +`; + +exports[`Validate Action check files "" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 2`] = `Array []`; + +exports[`Validate Action check files "" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 3`] = ` +Array [ + Array [ + "::warning::Unable to determine which files have changed, checking files: ** +", + ], + Array [ + "'fork' +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon) +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt) +", + ], + Array [ + "Files checked: 4, Issues found: 2 in 1 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::false +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::4 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::2 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::1 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} +", + ], + Array [ + "::error::2 spelling issues found in 1 of the 4 files checked. +", + ], +] +`; + +exports[`Validate Action check files "" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 4`] = ` +Array [ + "::warning::Unable to determine which files have changed, checking files: **", + "'fork'", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon)", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt)", + "Files checked: 4, Issues found: 2 in 1 files.", + "::set-output name=success::false", + "::set-output name=number_of_files_checked::4", + "::set-output name=number_of_issues::2", + "::set-output name=number_of_files_with_issues::1", + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]", + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", + "::error::2 spelling issues found in 1 of the 4 files checked.", +] +`; + +exports[`Validate Action check files "**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 1`] = ` +Array [ + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:19 Unknown word (Functon)", + "../fixtures/sampleCode/samples_with_errors/withErrors.ts:5:27 Unknown word (countt)", +] +`; + +exports[`Validate Action check files "**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 2`] = `Array []`; + +exports[`Validate Action check files "**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 3`] = ` +Array [ + Array [ + "::warning::Unable to determine which files have changed, checking files: ** +", + ], + Array [ + "'fork' +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon) +", + ], + Array [ + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt) +", + ], + Array [ + "Files checked: 4, Issues found: 2 in 1 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::false +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::4 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::2 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::1 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]} +", + ], + Array [ + "::error::2 spelling issues found in 1 of the 4 files checked. +", + ], +] +`; + +exports[`Validate Action check files "**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 4`] = ` +Array [ + "::warning::Unable to determine which files have changed, checking files: **", + "'fork'", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=19::Unknown word (Functon)", + "::warning file=../fixtures/sampleCode/samples_with_errors/withErrors.ts,line=5,col=27::Unknown word (countt)", + "Files checked: 4, Issues found: 2 in 1 files.", + "::set-output name=success::false", + "::set-output name=number_of_files_checked::4", + "::set-output name=number_of_issues::2", + "::set-output name=number_of_files_with_issues::1", + "::set-output name=files_with_issues::[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]", + "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":4,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", + "::error::2 spelling issues found in 1 of the 4 files checked.", +] +`; + +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: false pull_request_with_files.json, dot: "explicit" 1`] = `Array []`; + +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: false pull_request_with_files.json, dot: "explicit" 2`] = `Array []`; + +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: false pull_request_with_files.json, dot: "explicit" 3`] = ` +Array [ + Array [ + "Pull Request +", + ], + Array [ + "Files checked: 0, Issues found: 0 in 0 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::true +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::0 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::0 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::0 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":0,\\"files_with_issues\\":[]} +", + ], +] +`; + +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: false pull_request_with_files.json, dot: "explicit" 4`] = ` +Array [ + "Pull Request", + "Files checked: 0, Issues found: 0 in 0 files.", + "::set-output name=success::true", + "::set-output name=number_of_files_checked::0", + "::set-output name=number_of_issues::0", + "::set-output name=number_of_files_with_issues::0", + "::set-output name=files_with_issues::[]", + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":0,\\"files_with_issues\\":[]}", +] +`; + +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 1`] = `Array []`; -exports[`Validate Action check files with issues fixtures/sampleCode/** 6`] = `Array []`; +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 2`] = `Array []`; -exports[`Validate Action check files with issues fixtures/sampleCode/** 7`] = ` +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 3`] = ` Array [ Array [ "::warning::Unable to determine which files have changed, checking files: fixtures/sampleCode/** @@ -119,7 +589,7 @@ Array [ ", ], Array [ - "Files checked: 1, Issues found: 0 in 0 files. + "Files checked: 0, Issues found: 0 in 0 files. ", ], Array [ @@ -135,7 +605,7 @@ Array [ ", ], Array [ - "::set-output name=number_of_files_checked::1 + "::set-output name=number_of_files_checked::0 ", ], Array [ @@ -167,22 +637,22 @@ Array [ ", ], Array [ - "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":1,\\"files_with_issues\\":[]} + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":0,\\"files_with_issues\\":[]} ", ], ] `; -exports[`Validate Action check files with issues fixtures/sampleCode/** 8`] = ` +exports[`Validate Action check files "fixtures/sampleCode/**" incremental: true bad_params/bad_unsupported_event.json, dot: "explicit" 4`] = ` Array [ "::warning::Unable to determine which files have changed, checking files: fixtures/sampleCode/**", "'fork'", - "Files checked: 1, Issues found: 0 in 0 files.", + "Files checked: 0, Issues found: 0 in 0 files.", "::set-output name=success::true", - "::set-output name=number_of_files_checked::1", + "::set-output name=number_of_files_checked::0", "::set-output name=number_of_issues::0", "::set-output name=number_of_files_with_issues::0", "::set-output name=files_with_issues::[]", - "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":1,\\"files_with_issues\\":[]}", + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":0,\\"files_with_issues\\":[]}", ] `; diff --git a/action-src/src/action.test.ts b/action-src/src/action.test.ts index 0e9e87ba9..33e5caeba 100644 --- a/action-src/src/action.test.ts +++ b/action-src/src/action.test.ts @@ -11,7 +11,7 @@ import * as helper from './test/helper'; const configFile = path.resolve(root, 'cspell.json'); -const timeout = 20000; +const timeout = 30000; const spyLog = jest.spyOn(console, 'log').mockImplementation(() => {}); const spyWarn = jest.spyOn(console, 'warn').mockImplementation(() => {}); @@ -93,18 +93,27 @@ describe('Validate Action', () => { ); test.each` - files | incremental | contextFile | expected - ${'fixtures/sampleCode/**'} | ${false} | ${'pull_request_with_files.json'} | ${false} - ${'fixtures/sampleCode/**'} | ${true} | ${'bad_params/bad_unsupported_event.json'} | ${true} + files | incremental | dot | contextFile | expected + ${'fixtures/sampleCode/**'} | ${false} | ${'explicit'} | ${'pull_request_with_files.json'} | ${true} + ${'fixtures/sampleCode/**'} | ${true} | ${'explicit'} | ${'bad_params/bad_unsupported_event.json'} | ${true} + ${''} | ${true} | ${'explicit'} | ${'bad_params/bad_unsupported_event.json'} | ${false} + ${'**'} | ${true} | ${'explicit'} | ${'bad_params/bad_unsupported_event.json'} | ${false} + ${''} | ${false} | ${'explicit'} | ${'pull_request_with_files.json'} | ${false} + ${''} | ${false} | ${''} | ${'pull_request_with_files.json'} | ${false} + ${''} | ${false} | ${'true'} | ${'pull_request_with_files.json'} | ${false} `( - 'check files with issues $files', - async ({ files, incremental, contextFile, expected }) => { + 'check files "$files" incremental: $incremental $contextFile, dot: "$dot"', + async ({ files, incremental, contextFile, dot, expected }) => { const warnings: string[] = []; spyWarn.mockImplementation((msg: string) => warnings.push(msg)); - const context = createContextFromFile(contextFile, { + const params = { INPUT_FILES: files, INPUT_INCREMENTAL_FILES_ONLY: incremental ? 'true' : 'false', - }); + INPUT_CHECK_DOT_FILES: dot, + INPUT_ROOT: path.resolve(root, 'fixtures'), + INPUT_CONFIG: path.resolve(root, 'fixtures/cspell.json'), + }; + const context = createContextFromFile(contextFile, params); const octokit = createOctokit(); await expect(action(context, octokit)).resolves.toBe(expected); expect(warnings).toMatchSnapshot(); diff --git a/action-src/src/action.ts b/action-src/src/action.ts index 47e84456b..afce19e45 100644 --- a/action-src/src/action.ts +++ b/action-src/src/action.ts @@ -15,6 +15,7 @@ interface Context { github: Octokit; files: string; useEventFiles: boolean; + dot: boolean; } type EventNames = 'push' | 'pull_request'; @@ -88,7 +89,7 @@ function isSupportedEvent(eventName: EventNames | string): eventName is EventNam async function gatherFilesFromContext(context: Context): Promise> { if (context.useEventFiles) { const eventFiles = await gatherFiles(context); - return filterFiles(context.files, eventFiles); + return filterFiles(context.files, eventFiles, context.dot); } const files = new Set( @@ -116,12 +117,12 @@ async function gatherFiles(context: Context): Promise> { return new Set(); } -function filterFiles(globPattern: string, files: Set): Set { +function filterFiles(globPattern: string, files: Set, dot: boolean): Set { if (!globPattern) return files; const matchingFiles = new Set(); - const g = new glob.GlobMatcher(globPattern, { mode: 'include' }); + const g = new glob.GlobMatcher(globPattern, { mode: 'include', dot }); for (const p of files) { if (g.match(p)) { matchingFiles.add(p); @@ -146,11 +147,14 @@ export async function action(githubContext: GitHubContext, octokit: Octokit): Pr core.warning('Unable to determine which files have changed, checking files: ' + params.files); params.incremental_files_only = 'false'; } + params.files = params.files || (params.incremental_files_only !== 'true' ? '**' : ''); + const dot = !!checkDotMap[params.check_dot_files]; const context: Context = { githubContext, github: octokit, files: params.files, useEventFiles: params.incremental_files_only === 'true', + dot, }; core.info(friendlyEventName(eventName)); diff --git a/action-src/src/spell.test.ts b/action-src/src/spell.test.ts index 2b1f940ab..e43e13f10 100644 --- a/action-src/src/spell.test.ts +++ b/action-src/src/spell.test.ts @@ -57,10 +57,10 @@ describe('Validate Spell Checking', () => { ${'fixtures/sampleDotFiles/**'} | ${false} | ${[sc('ts/sample.ts')]} ${'fixtures/sampleDotFiles/**/.*.ts'} | ${undefined} | ${[sc('.dot_sample.ts')]} ${'fixtures/sampleDotFiles/**/.*.ts'} | ${true} | ${[sc('.dot_sample.ts')]} - ${'fixtures/sampleDotFiles/**/.*.ts'} | ${false} | ${[]} + ${'fixtures/sampleDotFiles/**/.*.ts'} | ${false} | ${[sc('.dot_sample.ts')]} ${'fixtures/sampleDotFiles/**/.*/**'} | ${undefined} | ${[sc('.dot_dir/sample_nested.ts')]} ${'fixtures/sampleDotFiles/**/.*/**'} | ${true} | ${[sc('.dot_dir/sample_nested.ts')]} - ${'fixtures/sampleDotFiles/**/.*/**'} | ${false} | ${[]} + ${'fixtures/sampleDotFiles/**/.*/**'} | ${false} | ${[sc('.dot_dir/sample_nested.ts')]} `('Linting checkDotFiles $glob $checkDotFiles', async ({ glob, checkDotFiles, expected }) => { const options = { root, diff --git a/action-src/src/spell.ts b/action-src/src/spell.ts index fc92d4dd9..a4de4b026 100644 --- a/action-src/src/spell.ts +++ b/action-src/src/spell.ts @@ -26,7 +26,6 @@ export async function lint(files: string[], lintOptions: LintOptions, reporter: options.dot = true; } else if (checkDotFiles === false) { options.dot = false; - options.exclude = ['.*']; } await cspellApp.lint(files, options, reporter); } diff --git a/action/lib/action.js b/action/lib/action.js index d8c0d91fd..e56e2059b 100644 --- a/action/lib/action.js +++ b/action/lib/action.js @@ -86,7 +86,7 @@ function isSupportedEvent(eventName) { async function gatherFilesFromContext(context) { if (context.useEventFiles) { const eventFiles = await gatherFiles(context); - return filterFiles(context.files, eventFiles); + return filterFiles(context.files, eventFiles, context.dot); } const files = new Set(context.files .split('\n') @@ -108,11 +108,11 @@ async function gatherFiles(context) { } return new Set(); } -function filterFiles(globPattern, files) { +function filterFiles(globPattern, files, dot) { if (!globPattern) return files; const matchingFiles = new Set(); - const g = new glob.GlobMatcher(globPattern, { mode: 'include' }); + const g = new glob.GlobMatcher(globPattern, { mode: 'include', dot }); for (const p of files) { if (g.match(p)) { matchingFiles.add(p); @@ -135,11 +135,14 @@ async function action(githubContext, octokit) { core.warning('Unable to determine which files have changed, checking files: ' + params.files); params.incremental_files_only = 'false'; } + params.files = params.files || (params.incremental_files_only !== 'true' ? '**' : ''); + const dot = !!checkDotMap[params.check_dot_files]; const context = { githubContext, github: octokit, files: params.files, useEventFiles: params.incremental_files_only === 'true', + dot, }; core.info(friendlyEventName(eventName)); const files = await gatherFilesFromContext(context); diff --git a/action/lib/spell.js b/action/lib/spell.js index 8a25970cb..e9b0c49dd 100644 --- a/action/lib/spell.js +++ b/action/lib/spell.js @@ -39,7 +39,6 @@ async function lint(files, lintOptions, reporter) { } else if (checkDotFiles === false) { options.dot = false; - options.exclude = ['.*']; } await cspellApp.lint(files, options, reporter); } diff --git a/cspell.json b/cspell.json index c1b827a6d..6f0bc8974 100644 --- a/cspell.json +++ b/cspell.json @@ -14,6 +14,7 @@ ], "useGitignore": true, "ignorePaths": [ + ".git/*", ".git/!{COMMIT_EDITMSG,EDITMSG}", ".git/*/**", ".yarn", diff --git a/fixtures/cspell.json b/fixtures/cspell.json index 3cca5d1d7..979afdfae 100644 --- a/fixtures/cspell.json +++ b/fixtures/cspell.json @@ -10,6 +10,9 @@ ], "globRoot": "./..", "ignorePaths": [ + ".git/*", + ".git/!{COMMIT_EDITMSG,EDITMSG}", + ".git/*/**", "node_modules", "action/", "cspell.json",