Skip to content

Commit

Permalink
[FEAT] Add tool to generate recommended config (typescript-eslint#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 authored and JamesHenry committed Jan 18, 2019
1 parent 9a2d3bc commit 0a858be
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
@@ -0,0 +1,6 @@
{
"rules": {
"class-name-casing": "error",
"no-unused-vars": "error"
}
}
8 changes: 7 additions & 1 deletion packages/eslint-plugin-typescript/lib/index.js
Expand Up @@ -16,4 +16,10 @@ const path = require("path");
//------------------------------------------------------------------------------

// import all rules in lib/rules
module.exports.rules = requireIndex(path.join(__dirname, "rules"));
module.exports = {
rules: requireIndex(path.join(__dirname, "rules")),
configs: {
// eslint-disable-next-line node/no-unpublished-require
recommended: require("./configs/recommended"),
},
};
9 changes: 5 additions & 4 deletions packages/eslint-plugin-typescript/package.json
Expand Up @@ -11,14 +11,15 @@
"author": "Nicholas C. Zakas",
"main": "lib/index.js",
"scripts": {
"lint": "eslint lib/ tests/",
"lint:fix": "eslint lib/ tests/ --fix",
"lint": "eslint lib/ tests/ tools/",
"lint:fix": "eslint lib/ tests/ tools/ --fix",
"docs": "eslint-docs",
"docs:check": "eslint-docs check",
"format-no-write": "prettier-eslint lib/**/*.js tests/**/*.js --eslint-config-path=.eslintrc --eslint-ignore --prettier-ignore --eslint-path=node_modules/eslint --config=.prettierrc",
"format-no-write": "prettier-eslint lib/**/*.js tests/**/*.js tools/**/*.js --eslint-config-path=.eslintrc --eslint-ignore --prettier-ignore --eslint-path=node_modules/eslint --config=.prettierrc",
"format": "yarn format-no-write --write",
"format-check": "yarn format-no-write --list-different",
"test": "mocha tests --recursive --reporter=dot"
"test": "mocha tests --recursive --reporter=dot",
"recommended:update": "node tools/update-recommended.js"
},
"dependencies": {
"requireindex": "^1.2.0",
Expand Down
26 changes: 26 additions & 0 deletions packages/eslint-plugin-typescript/tools/update-recommended.js
@@ -0,0 +1,26 @@
"use strict";

const path = require("path");
const fs = require("fs");
const requireIndex = require("requireindex");

/**
* Generate recommended configuration
* @returns {void}
*/
function generate() {
// replace this with Object.entries when node > 8
const allRules = requireIndex(path.resolve(__dirname, "../lib/rules"));
const rules = Object.keys(allRules)
.filter(key => allRules[key].meta.docs.recommended)
.reduce((config, item) => {
config[item] = "error";
return config;
}, {});

const filePath = path.resolve(__dirname, "../lib/configs/recommended.json");

fs.writeFileSync(filePath, `${JSON.stringify({ rules }, null, 4)}\n`);
}

generate();

0 comments on commit 0a858be

Please sign in to comment.