Skip to content

Commit 33d4ba9

Browse files
fix: Make sure the report default is undefined (#2475)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a445460 commit 33d4ba9

File tree

9 files changed

+139
-85
lines changed

9 files changed

+139
-85
lines changed

action-src/fixtures/reporting/samples_with_errors/cspell.config.yaml renamed to action-src/fixtures/reporting/cspell.config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import:
2-
- '../../cspell.json'
2+
- '../cspell.json'
33
files:
44
- '*.ts'
55
unknownWords: 'report-simple'

action-src/src/ActionParams.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('ActionParams', () => {
66
test.each`
77
params | expected
88
${{}} | ${__testing__.defaultActionParams}
9+
${{ report: '' }} | ${__testing__.defaultActionParams}
910
${{ strict: 'false' }} | ${{ ...__testing__.defaultActionParams, strict: 'false' }}
1011
`('applyDefaults $params', ({ params, expected }) => {
1112
expect(applyDefaults(params)).toEqual(expected);

action-src/src/ActionParams.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type { TrueFalse } from './utils.js';
99
*/
1010
type InlineWorkflowCommand = 'error' | 'warning' | 'none';
1111

12-
export type ActionParamsInput = Record<keyof ActionParams, string>;
12+
export type ActionParamsInput = Record<keyof ActionParams, string | undefined>;
1313

1414
export interface ActionParams {
1515
/**
@@ -69,7 +69,7 @@ export interface ActionParams {
6969
* 'simple' - only unknown words are reported.
7070
* 'typos' - only typos are reported.
7171
* 'flagged' - only flagged words are reported.
72-
* @default 'all'
72+
* default: use default reporting.
7373
*/
7474
report: ReportChoices;
7575
}
@@ -86,7 +86,7 @@ const defaultActionParams: ActionParams = {
8686
check_dot_files: 'explicit',
8787
use_cspell_files: 'false',
8888
suggestions: 'false',
89-
report: 'all',
89+
report: undefined,
9090
};
9191

9292
type ValidationFunction = (params: ActionParamsInput) => string | undefined;
@@ -116,7 +116,11 @@ function validateTrueFalse(key: keyof ActionParamsInput): ValidationFunction {
116116
return validateOptions(key, ['true', 'false']);
117117
}
118118

119-
function validateOptions(key: keyof ActionParamsInput, options: string[], optional?: boolean): ValidationFunction {
119+
function validateOptions<K extends keyof ActionParamsInput>(
120+
key: K,
121+
options: ActionParamsInput[K][],
122+
optional?: boolean,
123+
): ValidationFunction {
120124
return (params: ActionParamsInput) => {
121125
const value = params[key];
122126
if (optional && !value) {
@@ -148,7 +152,7 @@ export function validateActionParams(
148152
validateTrueFalse('use_cspell_files'),
149153
validateTrueFalse('suggestions'),
150154
validateOptions('check_dot_files', ['true', 'false', 'explicit']),
151-
validateOptions('report', ['all', 'simple', 'typos', 'flagged']),
155+
validateOptions('report', ['all', 'simple', 'typos', 'flagged'], true),
152156
];
153157
const success = validations
154158
.map((fn) => fn(params))

action-src/src/__snapshots__/action.test.ts.snap

Lines changed: 87 additions & 69 deletions
Large diffs are not rendered by default.

action-src/src/action.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,38 @@ describe('Validate Action', () => {
6262
});
6363

6464
test.each`
65-
files | expected
66-
${'**'} | ${false}
67-
${'**/*.md'} | ${true}
68-
`('check all $files', async ({ files, expected }) => {
65+
files | root | expected
66+
${'**'} | ${'fixtures'} | ${false}
67+
${'**/*.md'} | ${'fixtures'} | ${true}
68+
${'**'} | ${'fixtures/reporting'} | ${false}
69+
`('check all $files $root', async ({ files, root, expected }) => {
6970
const warnings: string[] = [];
7071
spyWarn.mockImplementation((_: string, msg: string) => warnings.push(msg));
7172
const context = createContextFromFile('pull_request.json', {
7273
INPUT_FILES: files,
7374
INPUT_INCREMENTAL_FILES_ONLY: 'false',
75+
INPUT_ROOT: path.resolve(sourceDir, root),
76+
});
77+
await expect(action(context)).resolves.toBe(expected);
78+
expect(warnings).toMatchSnapshot();
79+
expect(spyStdout).toHaveBeenCalled();
80+
});
81+
82+
test.each`
83+
files | report | root | expected
84+
${'**'} | ${''} | ${'fixtures/reporting'} | ${false}
85+
${'**'} | ${'all'} | ${'fixtures/reporting'} | ${false}
86+
${'**'} | ${'simple'} | ${'fixtures/reporting'} | ${false}
87+
${'**'} | ${'typos'} | ${'fixtures/reporting'} | ${false}
88+
${'**'} | ${'flagged'} | ${'fixtures/reporting'} | ${false}
89+
`('check with report $report $files $root', async ({ files, report, root, expected }) => {
90+
const warnings: string[] = [];
91+
spyWarn.mockImplementation((_: string, msg: string) => warnings.push(msg));
92+
const context = createContextFromFile('pull_request.json', {
93+
INPUT_FILES: files,
94+
INPUT_INCREMENTAL_FILES_ONLY: 'false',
95+
INPUT_ROOT: path.resolve(sourceDir, root),
96+
INPUT_REPORT: report,
7497
});
7598
await expect(action(context)).resolves.toBe(expected);
7699
expect(warnings).toMatchSnapshot();

action-src/src/reporter.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ import { createLogger } from './logger.js';
44
import { CSpellReporterForGithubAction } from './reporter.js';
55

66
describe('Validate Reporter', () => {
7-
test('Reporting Errors', () =>{
7+
test('Reporting Errors', () => {
88
const logger = createLogger({
99
debug: vi.fn(),
1010
info: vi.fn(),
1111
warning: vi.fn(),
1212
error: vi.fn(),
1313
});
1414

15-
const actionReporter = new CSpellReporterForGithubAction('none', { verbose: false, treatFlaggedWordsAsErrors: true }, logger);
15+
const actionReporter = new CSpellReporterForGithubAction(
16+
'none',
17+
{ verbose: false, treatFlaggedWordsAsErrors: true },
18+
logger,
19+
);
1620
const reporter = actionReporter.reporter;
1721

1822
reporter.error?.('This is an error message', new Error('Test error'));

action-src/src/spell.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import type { CSpellReporter } from 'cspell';
22
import { type CSpellApplicationOptions, lint as cspellAppLint } from 'cspell';
33

4-
export type ReportChoices = 'all' | 'simple' | 'typos' | 'flagged';
4+
export type ReportChoices =
5+
| 'all' // all issues are reported
6+
| 'simple' // only simple misspellings, typos, and flagged words
7+
| 'typos' // only typos/misspellings, and flagged words
8+
| 'flagged' // only flagged/forbidden words
9+
| undefined; // use default reporting;
510
export interface LintOptions {
611
root: string;
712
config?: string;

action-src/src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
export type TrueFalse = 'true' | 'false';
32

43
/**

action/lib/main_root.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37320,7 +37320,7 @@ var defaultActionParams = {
3732037320
check_dot_files: "explicit",
3732137321
use_cspell_files: "false",
3732237322
suggestions: "false",
37323-
report: "all"
37323+
report: void 0
3732437324
};
3732537325
function applyDefaults(params) {
3732637326
const results = { ...defaultActionParams, ...params };
@@ -37365,7 +37365,7 @@ function validateActionParams(params, logError2) {
3736537365
validateTrueFalse("use_cspell_files"),
3736637366
validateTrueFalse("suggestions"),
3736737367
validateOptions("check_dot_files", ["true", "false", "explicit"]),
37368-
validateOptions("report", ["all", "simple", "typos", "flagged"])
37368+
validateOptions("report", ["all", "simple", "typos", "flagged"], true)
3736937369
];
3737037370
const success = validations.map((fn) => fn(params)).map((msg) => !msg || (logError2(msg), false)).reduce((a, b) => a && b, true);
3737137371
if (!success) {

0 commit comments

Comments
 (0)