Created
March 1, 2016 20:19
-
-
Save tlrobinson/6b9ef85bb6a3804526af to your computer and use it in GitHub Desktop.
Runs ESLint with every rule enabled, prints sorted list of number of violations of each rule
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
#!/usr/bin/env node | |
/* eslint-disable */ | |
var fs = require("fs"); | |
var glob = require("glob"); | |
var linter = require("eslint").linter; | |
var SOURCES = glob.sync("frontend/src/**/*.js*"); | |
var ESLINT_RULES = Object.keys(require('eslint/conf/eslint.json').rules); | |
var ESLINT_REACT_RULES = Object.keys(require('eslint-plugin-react').rules); | |
var ALL_RULES = [].concat(ESLINT_RULES, ESLINT_REACT_RULES) | |
console.log("files", SOURCES.length, "rules", ALL_RULES.length); | |
var config = JSON.parse(fs.readFileSync(".eslintrc")); | |
config.rules = {} | |
for (var rule of ESLINT_RULES) { | |
config.rules[rule] = 2; | |
} | |
var ruleCounts = {} | |
for (var file of SOURCES) { | |
var code = fs.readFileSync(file, "utf-8"); | |
var messages = linter.verify(code, config, { filename: file, allowInlineConfig: false }); | |
for (var message of messages) { | |
ruleCounts[message.ruleId] = (ruleCounts[message.ruleId] || 0) + 1; | |
} | |
console.log(file, messages.length); | |
} | |
Object.keys(ruleCounts) | |
.map(ruleId => [ruleId, ruleCounts[ruleId]]) | |
.sort((a,b) => a[1] - b[1]) | |
.forEach((rule) => console.log(rule[1], rule[0])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment