Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import:
- '../../cspell.json'
- '../cspell.json'
files:
- '*.ts'
unknownWords: 'report-simple'
Expand Down
1 change: 1 addition & 0 deletions action-src/src/ActionParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('ActionParams', () => {
test.each`
params | expected
${{}} | ${__testing__.defaultActionParams}
${{ report: '' }} | ${__testing__.defaultActionParams}
${{ strict: 'false' }} | ${{ ...__testing__.defaultActionParams, strict: 'false' }}
`('applyDefaults $params', ({ params, expected }) => {
expect(applyDefaults(params)).toEqual(expected);
Expand Down
14 changes: 9 additions & 5 deletions action-src/src/ActionParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { TrueFalse } from './utils.js';
*/
type InlineWorkflowCommand = 'error' | 'warning' | 'none';

export type ActionParamsInput = Record<keyof ActionParams, string>;
export type ActionParamsInput = Record<keyof ActionParams, string | undefined>;

export interface ActionParams {
/**
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface ActionParams {
* 'simple' - only unknown words are reported.
* 'typos' - only typos are reported.
* 'flagged' - only flagged words are reported.
* @default 'all'
* default: use default reporting.
*/
report: ReportChoices;
}
Expand All @@ -86,7 +86,7 @@ const defaultActionParams: ActionParams = {
check_dot_files: 'explicit',
use_cspell_files: 'false',
suggestions: 'false',
report: 'all',
report: undefined,
};

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

function validateOptions(key: keyof ActionParamsInput, options: string[], optional?: boolean): ValidationFunction {
function validateOptions<K extends keyof ActionParamsInput>(
key: K,
options: ActionParamsInput[K][],
optional?: boolean,
): ValidationFunction {
return (params: ActionParamsInput) => {
const value = params[key];
if (optional && !value) {
Expand Down Expand Up @@ -148,7 +152,7 @@ export function validateActionParams(
validateTrueFalse('use_cspell_files'),
validateTrueFalse('suggestions'),
validateOptions('check_dot_files', ['true', 'false', 'explicit']),
validateOptions('report', ['all', 'simple', 'typos', 'flagged']),
validateOptions('report', ['all', 'simple', 'typos', 'flagged'], true),
];
const success = validations
.map((fn) => fn(params))
Expand Down
156 changes: 87 additions & 69 deletions action-src/src/__snapshots__/action.test.ts.snap

Large diffs are not rendered by default.

31 changes: 27 additions & 4 deletions action-src/src/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,38 @@ describe('Validate Action', () => {
});

test.each`
files | expected
${'**'} | ${false}
${'**/*.md'} | ${true}
`('check all $files', async ({ files, expected }) => {
files | root | expected
${'**'} | ${'fixtures'} | ${false}
${'**/*.md'} | ${'fixtures'} | ${true}
${'**'} | ${'fixtures/reporting'} | ${false}
`('check all $files $root', async ({ files, root, expected }) => {
const warnings: string[] = [];
spyWarn.mockImplementation((_: string, msg: string) => warnings.push(msg));
const context = createContextFromFile('pull_request.json', {
INPUT_FILES: files,
INPUT_INCREMENTAL_FILES_ONLY: 'false',
INPUT_ROOT: path.resolve(sourceDir, root),
});
await expect(action(context)).resolves.toBe(expected);
expect(warnings).toMatchSnapshot();
expect(spyStdout).toHaveBeenCalled();
});

test.each`
files | report | root | expected
${'**'} | ${''} | ${'fixtures/reporting'} | ${false}
${'**'} | ${'all'} | ${'fixtures/reporting'} | ${false}
${'**'} | ${'simple'} | ${'fixtures/reporting'} | ${false}
${'**'} | ${'typos'} | ${'fixtures/reporting'} | ${false}
${'**'} | ${'flagged'} | ${'fixtures/reporting'} | ${false}
`('check with report $report $files $root', async ({ files, report, root, expected }) => {
const warnings: string[] = [];
spyWarn.mockImplementation((_: string, msg: string) => warnings.push(msg));
const context = createContextFromFile('pull_request.json', {
INPUT_FILES: files,
INPUT_INCREMENTAL_FILES_ONLY: 'false',
INPUT_ROOT: path.resolve(sourceDir, root),
INPUT_REPORT: report,
});
await expect(action(context)).resolves.toBe(expected);
expect(warnings).toMatchSnapshot();
Expand Down
8 changes: 6 additions & 2 deletions action-src/src/reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import { createLogger } from './logger.js';
import { CSpellReporterForGithubAction } from './reporter.js';

describe('Validate Reporter', () => {
test('Reporting Errors', () =>{
test('Reporting Errors', () => {
const logger = createLogger({
debug: vi.fn(),
info: vi.fn(),
warning: vi.fn(),
error: vi.fn(),
});

const actionReporter = new CSpellReporterForGithubAction('none', { verbose: false, treatFlaggedWordsAsErrors: true }, logger);
const actionReporter = new CSpellReporterForGithubAction(
'none',
{ verbose: false, treatFlaggedWordsAsErrors: true },
logger,
);
const reporter = actionReporter.reporter;

reporter.error?.('This is an error message', new Error('Test error'));
Expand Down
7 changes: 6 additions & 1 deletion action-src/src/spell.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import type { CSpellReporter } from 'cspell';
import { type CSpellApplicationOptions, lint as cspellAppLint } from 'cspell';

export type ReportChoices = 'all' | 'simple' | 'typos' | 'flagged';
export type ReportChoices =
| 'all' // all issues are reported
| 'simple' // only simple misspellings, typos, and flagged words
| 'typos' // only typos/misspellings, and flagged words
| 'flagged' // only flagged/forbidden words
| undefined; // use default reporting;
export interface LintOptions {
root: string;
config?: string;
Expand Down
1 change: 0 additions & 1 deletion action-src/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export type TrueFalse = 'true' | 'false';

/**
Expand Down
4 changes: 2 additions & 2 deletions action/lib/main_root.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -37320,7 +37320,7 @@ var defaultActionParams = {
check_dot_files: "explicit",
use_cspell_files: "false",
suggestions: "false",
report: "all"
report: void 0
};
function applyDefaults(params) {
const results = { ...defaultActionParams, ...params };
Expand Down Expand Up @@ -37365,7 +37365,7 @@ function validateActionParams(params, logError2) {
validateTrueFalse("use_cspell_files"),
validateTrueFalse("suggestions"),
validateOptions("check_dot_files", ["true", "false", "explicit"]),
validateOptions("report", ["all", "simple", "typos", "flagged"])
validateOptions("report", ["all", "simple", "typos", "flagged"], true)
];
const success = validations.map((fn) => fn(params)).map((msg) => !msg || (logError2(msg), false)).reduce((a, b) => a && b, true);
if (!success) {
Expand Down
Loading