-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚦 Change severity of the error messages (#1104)
This adds a `error_rules` to the project configuration, which can be used to disable logging rules in the CLI.
- Loading branch information
Showing
20 changed files
with
274 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"myst-config": patch | ||
"myst-cli": patch | ||
--- | ||
|
||
Add error_rules to turn off warnings and errors in the CLI. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
title: Error Rules | ||
kind: config | ||
cases: | ||
- title: error rules | ||
raw: | ||
error_rules: | ||
- math-eqnarray-replaced | ||
normalized: | ||
error_rules: | ||
- id: math-eqnarray-replaced | ||
severity: ignore | ||
- title: error rules - incorrect severity | ||
raw: | ||
error_rules: | ||
- rule: math-eqnarray-replaced | ||
severity: nope | ||
normalized: | ||
error_rules: [] | ||
errors: 1 | ||
- title: error rules with params | ||
raw: | ||
error_rules: | ||
- rule: a-rule | ||
keys: | ||
- one | ||
- two | ||
normalized: | ||
error_rules: | ||
- id: a-rule | ||
severity: ignore | ||
key: one | ||
- id: a-rule | ||
severity: ignore | ||
key: two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './types.js'; | ||
export * from './validators.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type ErrorRule = { | ||
id: string; | ||
severity: 'ignore' | 'warn' | 'error'; | ||
key?: string; | ||
} & Record<string, any>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { ValidationOptions } from 'simple-validators'; | ||
import { | ||
defined, | ||
incrementOptions, | ||
validateChoice, | ||
validateList, | ||
validateObjectKeys, | ||
validateString, | ||
} from 'simple-validators'; | ||
import type { ErrorRule } from './types.js'; | ||
|
||
const ERROR_RULE_KEY_OBJECT = { | ||
required: ['id'], | ||
optional: ['severity', 'keys'], | ||
alias: { | ||
rule: 'id', | ||
key: 'keys', | ||
}, | ||
}; | ||
|
||
export function validateErrorRule(input: any, opts: ValidationOptions): ErrorRule[] | undefined { | ||
if (typeof input === 'string') { | ||
input = { id: input }; | ||
} | ||
const value = validateObjectKeys(input, ERROR_RULE_KEY_OBJECT, { | ||
...opts, | ||
}); | ||
if (value === undefined) return undefined; | ||
const id = validateString(value.id, incrementOptions('id', opts)); | ||
const severity = validateChoice(value.severity || 'ignore', { | ||
...incrementOptions('severity', opts), | ||
choices: ['ignore', 'warn', 'error'], | ||
}) as ErrorRule['severity']; | ||
if (!id || !severity) return undefined; | ||
const output: ErrorRule = { id, severity }; | ||
if (!defined(value.keys)) return [output]; | ||
// We now have either a list of keys or a single key | ||
// validate and unpack to a separate error rule | ||
const keyList = validateList( | ||
value.keys, | ||
{ ...incrementOptions('keys', opts), coerce: true }, | ||
(key, ind) => { | ||
return validateString(key, incrementOptions(`keys.${ind}`, opts)); | ||
}, | ||
); | ||
if (!keyList) return undefined; | ||
return keyList.map((key) => ({ ...output, key })); | ||
} | ||
|
||
export function validateErrorRuleList( | ||
input: any, | ||
opts: ValidationOptions, | ||
): ErrorRule[] | undefined { | ||
if (input === undefined) return undefined; | ||
const output = validateList( | ||
input, | ||
{ coerce: true, ...incrementOptions('error_rules', opts) }, | ||
(exp, ind) => { | ||
return validateErrorRule(exp, incrementOptions(`error_rules.${ind}`, opts)); | ||
}, | ||
); | ||
if (!output) return undefined; | ||
return output.flat(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.