Skip to content

Commit

Permalink
chore: add script for identify undefined rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Nov 20, 2020
1 parent 96ca5d3 commit 26159ee
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bin/.eslintrc.js
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),
};
49 changes: 49 additions & 0 deletions bin/identify-undefined-rules.js
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/'
);
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"acorn": "8.0.4",
"eslint": "7.13.0",
"eslint-plugin-import": "2.22.1",
"node-fetch": "2.6.1",
"npm-check-updates": "10.2.1",
"npm-run-all": "4.1.5",
"prettier": "2.1.2",
Expand Down

0 comments on commit 26159ee

Please sign in to comment.