Skip to content

Commit

Permalink
feat(cli): drop --skip-rule and --show-unmatched-globs flags (#1560)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip authored Mar 26, 2021
1 parent 4a5c6fd commit b78e2f1
Show file tree
Hide file tree
Showing 13 changed files with 10 additions and 149 deletions.
3 changes: 0 additions & 3 deletions docs/guides/2-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ Other options include:
--output, -o output to a file instead of stdout [string]
--resolver path to custom json-ref-resolver instance [string]
--ruleset, -r path/URL to a ruleset file [string]
--skip-rule, -s ignore certain rules if they are causing trouble [string]
--fail-severity, -F results of this level or above will trigger a failure exit code
[string] [choices: "error", "warn", "info", "hint"] [default: "error"]
--display-only-failures, -D only output results equal to or greater than --fail-severity
[boolean] [default: false]
--ignore-unknown-format do not warn about unmatched formats [boolean] [default: false]
--show-unmatched-globs show unmatched glob patterns
[deprecated: use --fail-on-unmatched-globs] [boolean] [default: false]
--fail-on-unmatched-globs fail on unmatched glob patterns [boolean] [default: false]
--verbose, -v increase verbosity [boolean]
--quiet, -q no logging - output only [boolean]
Expand Down
7 changes: 7 additions & 0 deletions docs/migration-guides/6.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Spectral v5 to v6 Migration Guide (WIP)

## CLI

1. deprecated `--show-unmatched-globs` flag has been removed. Alternative available: `--fail-on-unmatched-globs`

2. `--skip-rule` has been removed. Use a custom ruleset instead.
29 changes: 0 additions & 29 deletions src/cli/commands/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('lint', () => {
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});
Expand All @@ -95,7 +94,6 @@ describe('lint', () => {
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});
Expand All @@ -107,7 +105,6 @@ describe('lint', () => {
encoding: 'utf16',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});
Expand All @@ -119,7 +116,6 @@ describe('lint', () => {
encoding: 'utf16',
format: 'json',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});
Expand Down Expand Up @@ -161,36 +157,12 @@ describe('lint', () => {
expect(writeOutput).toBeCalledWith('<formatted output>', 'foo.json');
});

it('passes skip-rule to lint', async () => {
await run('lint --skip-rule foo --skip-rule bar ./__fixtures__/empty-oas2-document.json');
expect(lint).toHaveBeenCalledWith([expect.any(String)], {
skipRule: ['foo', 'bar'],
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});

it('passes ignore-unknown-format to lint', async () => {
await run('lint --ignore-unknown-format ./__fixtures__/empty-oas2-document.json');
expect(lint).toHaveBeenCalledWith([expect.any(String)], {
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: true,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: false,
});
});

it('passes show-unmatched-globs to lint', async () => {
await run('lint --show-unmatched-globs ./__fixtures__/empty-oas2-document.json');
expect(lint).toHaveBeenCalledWith([expect.any(String)], {
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: true,
failOnUnmatchedGlobs: false,
});
});
Expand All @@ -201,7 +173,6 @@ describe('lint', () => {
encoding: 'utf8',
format: 'stylish',
ignoreUnknownFormat: false,
showUnmatchedGlobs: false,
failOnUnmatchedGlobs: true,
});
});
Expand Down
16 changes: 1 addition & 15 deletions src/cli/commands/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ const lintCommand: CommandModule = {
type: 'string',
coerce: toArray,
},
'skip-rule': {
alias: 's',
description: 'ignore certain rules if they are causing trouble',
type: 'string',
coerce: toArray,
},
'fail-severity': {
alias: 'F',
description: 'results of this level or above will trigger a failure exit code',
Expand All @@ -105,12 +99,6 @@ const lintCommand: CommandModule = {
type: 'boolean',
default: false,
},
'show-unmatched-globs': {
description: 'show unmatched glob patterns',
type: 'boolean',
default: false,
deprecated: 'use --fail-on-unmatched-globs',
},
'fail-on-unmatched-globs': {
description: 'fail on unmatched glob patterns',
type: 'boolean',
Expand Down Expand Up @@ -138,7 +126,6 @@ const lintCommand: CommandModule = {
output,
encoding,
ignoreUnknownFormat,
showUnmatchedGlobs,
failOnUnmatchedGlobs,
...config
} = (args as unknown) as ILintConfig & {
Expand All @@ -153,9 +140,8 @@ const lintCommand: CommandModule = {
encoding,
ignoreUnknownFormat,
failOnUnmatchedGlobs,
showUnmatchedGlobs,
ruleset,
...pick<Partial<ILintConfig>, keyof ILintConfig>(config, ['skipRule', 'verbose', 'quiet', 'resolver']),
...pick<Partial<ILintConfig>, keyof ILintConfig>(config, ['verbose', 'quiet', 'resolver']),
})
.then(results => {
if (displayOnlyFailures) {
Expand Down
18 changes: 0 additions & 18 deletions src/cli/services/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,6 @@ describe('Linter service', () => {
]),
);
});

describe('and --skip-rule=info-contact is set', () => {
it('output other warnings but not info-contact', async () => {
const output = await run(`lint --skip-rule=info-contact ${document}`);

expect(output).toEqual(expect.arrayContaining([expect.objectContaining({ code: 'oas3-api-servers' })]));
expect(output).toEqual(expect.not.arrayContaining([expect.objectContaining({ code: 'info-contact' })]));
});
});

describe('and --skip-rule=info-contact --skip-rule=oas3-api-servers is set', () => {
it('outputs neither info-contact or oas3-api-servers', async () => {
const output = await run(`lint --skip-rule=info-contact --skip-rule=oas3-api-servers ${document}`);

expect(output).toEqual(expect.not.arrayContaining([expect.objectContaining({ code: 'info-contact' })]));
expect(output).toEqual(expect.not.arrayContaining([expect.objectContaining({ code: 'oas3-api-servers' })]));
});
});
});
});

Expand Down
11 changes: 2 additions & 9 deletions src/cli/services/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { readParsable, IFileReadOptions } from '../../../fs/reader';
import * as Parsers from '../../../parsers';
import { IRuleResult, Spectral } from '../../../spectral';
import { ILintConfig } from '../../../types/config';
import { getRuleset, listFiles, skipRules, segregateEntriesPerKind, readFileDescriptor } from './utils';
import { getRuleset, listFiles, segregateEntriesPerKind, readFileDescriptor } from './utils';
import { getResolver } from './utils/getResolver';
import { YamlParserResult } from '@stoplight/yaml';
import { DEFAULT_REQUEST_OPTIONS } from '../../../request';
Expand Down Expand Up @@ -45,15 +45,8 @@ export async function lint(documents: Array<number | string>, flags: ILintConfig
}
}

if (flags.skipRule !== void 0) {
spectral.setRules(skipRules(ruleset.rules, flags));
}

const [globs, fileDescriptors] = segregateEntriesPerKind(documents);
const [targetUris, unmatchedPatterns] = await listFiles(
globs,
!(flags.showUnmatchedGlobs || flags.failOnUnmatchedGlobs),
);
const [targetUris, unmatchedPatterns] = await listFiles(globs, !flags.failOnUnmatchedGlobs);
const results: IRuleResult[] = [];

if (unmatchedPatterns.length > 0) {
Expand Down
1 change: 0 additions & 1 deletion src/cli/services/linter/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export * from './getRuleset';
export * from './listFiles';
export * from './readFileDescriptor';
export * from './segregateEntriesPerKind';
export * from './skipRules';
28 changes: 0 additions & 28 deletions src/cli/services/linter/utils/skipRules.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export interface ILintConfig {
output?: string;
resolver?: string;
ruleset?: string[];
skipRule?: string[];
ignoreUnknownFormat: boolean;
showUnmatchedGlobs: boolean;
failOnUnmatchedGlobs: boolean;
verbose?: boolean;
quiet?: boolean;
Expand Down
2 changes: 0 additions & 2 deletions test-harness/scenarios/help-no-document.scenario
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ Options:
-o, --output output to a file instead of stdout [string]
--resolver path to custom json-ref-resolver instance [string]
-r, --ruleset path/URL to a ruleset file [string]
-s, --skip-rule ignore certain rules if they are causing trouble [string]
-F, --fail-severity results of this level or above will trigger a failure exit code [string] [choices: "error", "warn", "info", "hint"] [default: "error"]
-D, --display-only-failures only output results equal to or greater than --fail-severity [boolean] [default: false]
--ignore-unknown-format do not warn about unmatched formats [boolean] [default: false]
--show-unmatched-globs show unmatched glob patterns [deprecated: use --fail-on-unmatched-globs] [boolean] [default: false]
--fail-on-unmatched-globs fail on unmatched glob patterns [boolean] [default: false]
-v, --verbose increase verbosity [boolean]
-q, --quiet no logging - output only [boolean]
18 changes: 0 additions & 18 deletions test-harness/scenarios/results-skip-rule.oas3.scenario

This file was deleted.

17 changes: 0 additions & 17 deletions test-harness/scenarios/results-skip-rules-multiple.oas3.scenario

This file was deleted.

7 changes: 0 additions & 7 deletions test-harness/scenarios/unmatched-glob-patterns.scenario

This file was deleted.

0 comments on commit b78e2f1

Please sign in to comment.