forked from typescript-eslint/typescript-eslint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(eslint-plugin): add config validation script to CI (typescript-…
…eslint#649) * chore(eslint-plugin): add config validation script to CI * chore: correct docs
- Loading branch information
1 parent
a5398ce
commit c2ad091
Showing
13 changed files
with
107 additions
and
11 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
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
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
packages/eslint-plugin/tools/validate-configs/checkConfigAll.ts
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,35 @@ | ||
import plugin from '../../src/index'; | ||
import { logRule } from '../log'; | ||
|
||
const prefix = '@typescript-eslint/'; | ||
|
||
function checkConfigAll() { | ||
const { rules } = plugin; | ||
|
||
const all = plugin.configs.all.rules; | ||
const allNames = new Set(Object.keys(all)); | ||
|
||
return Object.entries(rules).reduce((acc, [ruleName, rule]) => { | ||
if (!rule.meta.deprecated) { | ||
const prefixed = `${prefix}${ruleName}` as keyof typeof all; | ||
if (allNames.has(prefixed)) { | ||
if (all[prefixed] !== 'error') { | ||
logRule( | ||
false, | ||
ruleName, | ||
'incorrect setting compared to the rule meta.', | ||
); | ||
return true; | ||
} | ||
} else { | ||
logRule(false, ruleName, 'missing in the config.'); | ||
return true; | ||
} | ||
} | ||
|
||
logRule(true, ruleName); | ||
return acc; | ||
}, false); | ||
} | ||
|
||
export { checkConfigAll }; |
35 changes: 35 additions & 0 deletions
35
packages/eslint-plugin/tools/validate-configs/checkConfigRecommended.ts
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,35 @@ | ||
import plugin from '../../src/index'; | ||
import { logRule } from '../log'; | ||
|
||
const prefix = '@typescript-eslint/'; | ||
|
||
function checkConfigRecommended() { | ||
const { rules } = plugin; | ||
|
||
const recommended = plugin.configs.recommended.rules; | ||
const recommendedNames = new Set(Object.keys(recommended)); | ||
|
||
return Object.entries(rules).reduce((acc, [ruleName, rule]) => { | ||
if (!rule.meta.deprecated && rule.meta.docs.recommended !== false) { | ||
const prefixed = `${prefix}${ruleName}` as keyof typeof recommended; | ||
if (recommendedNames.has(prefixed)) { | ||
if (recommended[prefixed] !== rule.meta.docs.recommended) { | ||
logRule( | ||
false, | ||
ruleName, | ||
'incorrect setting compared to the rule meta.', | ||
); | ||
return true; | ||
} | ||
} else { | ||
logRule(false, ruleName, 'missing in the config.'); | ||
return true; | ||
} | ||
} | ||
|
||
logRule(true, ruleName); | ||
return acc; | ||
}, false); | ||
} | ||
|
||
export { checkConfigRecommended }; |
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,22 @@ | ||
import chalk from 'chalk'; | ||
import { checkConfigRecommended } from './checkConfigRecommended'; | ||
import { checkConfigAll } from './checkConfigAll'; | ||
|
||
let hasErrors = false; | ||
console.log(chalk.underline('Checking config "recommended"')); | ||
hasErrors = checkConfigRecommended() || hasErrors; | ||
|
||
console.log(); | ||
console.log(chalk.underline('Checking config "all"')); | ||
hasErrors = checkConfigAll() || hasErrors; | ||
|
||
if (hasErrors) { | ||
console.log('\n\n'); | ||
console.error( | ||
chalk.bold.bgRed.white('There were errors found in the configs'), | ||
); | ||
console.error(`Please run ${chalk.inverse('yarn generate:configs')}`); | ||
console.log('\n\n'); | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/eslint-plugin/tools/validate-docs/check-for-rule-docs.ts
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
2 changes: 1 addition & 1 deletion
2
packages/eslint-plugin/tools/validate-docs/validate-table-structure.ts
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