-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add script for identify undefined rules
- Loading branch information
Simon Mollweide
committed
Nov 20, 2020
1 parent
96ca5d3
commit 26159ee
Showing
4 changed files
with
57 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
"extends": "../configurations/es5-node.js" | ||
extends: ['../configurations/es5-node.js', '../configurations/es5-node-disable-styles.js'].map(require.resolve), | ||
}; |
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,49 @@ | ||
/* eslint-disable no-console */ | ||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
// eslint-disable-next-line no-redeclare | ||
const fetch = require('node-fetch'); | ||
|
||
const appendPrefix = (prefix) => (val) => `${prefix}${val}`; | ||
const ruleNotDefined = (ruleSet) => (val) => Boolean(!ruleSet[val]); | ||
const prettyPrint = (val) => `- ${val}`; | ||
|
||
/** | ||
* @param {string} pathRules - path to the rule js file | ||
* @param {string} url - url: for example https://github.com/eslint/eslint/tree/master/docs/rules | ||
* @param {string} prefix - rule prefix for example "@typescript-eslint/" | ||
* @returns {void} | ||
*/ | ||
async function identifyUndefinedRules(pathRules, url, prefix) { | ||
const cwd = await fs.realpath(process.cwd()); | ||
// eslint-disable-next-line global-require | ||
const rulesFile = await require(path.join(cwd, pathRules)); | ||
const checkForRules = []; | ||
const checkForFile = await (await fetch(url)).text(); | ||
|
||
const regex1 = /([^>]*)(\.md)(<\/a>)/g; | ||
let arr; | ||
|
||
// eslint-disable-next-line no-cond-assign | ||
while ((arr = regex1.exec(checkForFile)) !== null) { | ||
checkForRules.push(appendPrefix(prefix)(arr[1])); | ||
} | ||
|
||
const missingRules = checkForRules.filter(ruleNotDefined(rulesFile.rules)); | ||
|
||
if (missingRules.length <= 0) { | ||
console.log('All rules are defined'); | ||
} | ||
|
||
console.log(`\nThe following ${missingRules.length} rules are not defined:\n`); | ||
console.log(missingRules.map(prettyPrint).join('\n')); | ||
} | ||
|
||
// eslint: https://github.com/eslint/eslint/tree/master/docs/rules | ||
// typescript: https://github.com/eslint/eslint/tree/master/docs/rules | ||
|
||
identifyUndefinedRules( | ||
'./rules/typescript.js', | ||
'https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin/docs/rules', | ||
'@typescript-eslint/' | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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