-
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.
Merge pull request #27 from sarbbottam/refactor
Refactor
- Loading branch information
Showing
17 changed files
with
242 additions
and
228 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "eslint-find-new-rules", | ||
"version": "0.0.0-semantically-released", | ||
"description": "Find built-in ESLint rules you don't have in your custom config.", | ||
"main": "index.js", | ||
"main": "src/rule-finder.js", | ||
"scripts": { | ||
"cover": "nyc --reporter=lcov --reporter=text ava", | ||
"test": "ava", | ||
|
@@ -16,7 +16,7 @@ | |
"report-coverage": "cat ./coverage/lcov.info | node_modules/.bin/codecov" | ||
}, | ||
"bin": { | ||
"eslint-find-new-rules": "bin.js" | ||
"eslint-find-new-rules": "src/bin.js" | ||
}, | ||
"keywords": [], | ||
"author": "Michał Gołębiowski <[email protected]>", | ||
|
@@ -78,4 +78,4 @@ | |
"url": "https://github.com/kentcdodds/eslint-find-new-rules/issues" | ||
}, | ||
"homepage": "https://github.com/kentcdodds/eslint-find-new-rules#readme" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
var path = require('path') | ||
var fs = require('fs') | ||
|
||
var eslint = require('eslint') | ||
var isAbsolute = require('path-is-absolute') | ||
var difference = require('lodash.difference') | ||
|
||
function _getConfigFile(specifiedFile) { | ||
if (specifiedFile) { | ||
if (isAbsolute(specifiedFile)) { | ||
return specifiedFile | ||
} else { | ||
return path.join(process.cwd(), specifiedFile) | ||
} | ||
} else { | ||
// this is not being called with an arg. Use the package.json `main` | ||
return require(path.join(process.cwd(), 'package.json')).main | ||
} | ||
} | ||
|
||
function _getConfig(configFile) { | ||
var cliEngine = new eslint.CLIEngine({ | ||
// ignore any config applicable depending on the location on the filesystem | ||
useEslintrc: false, | ||
// point to the particular config | ||
configFile: configFile, // eslint-disable-line object-shorthand | ||
}) | ||
return cliEngine.getConfigForFile() | ||
} | ||
|
||
function _getCurrentRules(config) { | ||
return Object.keys(config.rules) | ||
} | ||
|
||
function _getPluginRules(config) { | ||
var pluginRules = [] | ||
var plugins = config.plugins | ||
if (plugins) { | ||
plugins.forEach(function getPluginRule(plugin) { | ||
var pluginConfig = require('eslint-plugin-' + plugin) | ||
var rules = pluginConfig.rules | ||
pluginRules = pluginRules.concat( | ||
Object.keys(rules).map(function normalizePluginRule(rule) { | ||
return plugin + '/' + rule | ||
}) | ||
) | ||
}) | ||
} | ||
return pluginRules | ||
} | ||
|
||
function _getAllAvailableRules(pluginRules) { | ||
var allRules = fs | ||
.readdirSync('./node_modules/eslint/lib/rules') | ||
.map(function removeJsFromFilename(filename) { | ||
return filename.replace(/\.js$/, '') | ||
}) | ||
|
||
allRules = allRules.concat(pluginRules) | ||
|
||
return allRules | ||
} | ||
|
||
function RuleFinder(specifiedFile) { | ||
var configFile = _getConfigFile(specifiedFile) | ||
var config = _getConfig(configFile) | ||
var currentRules = _getCurrentRules(config) | ||
var pluginRules = _getPluginRules(config) | ||
var allRules = _getAllAvailableRules(pluginRules) | ||
var unusedRules = difference(allRules, currentRules) | ||
|
||
// get all the current rules instead of referring the extended files or documentation | ||
this.getCurrentRules = function getCurrentRules() { | ||
return currentRules | ||
} | ||
|
||
// get all the plugin rules instead of referring the extended files or documentation | ||
this.getPluginRules = function getPluginRules() { | ||
return pluginRules | ||
} | ||
|
||
// get all the availale rules instead of referring eslint and pluging packages or documentation | ||
this.getAllAvailableRules = function getAllAvailableRules() { | ||
return allRules | ||
} | ||
|
||
this.getUnusedRules = function getUnusedRules() { | ||
return unusedRules | ||
} | ||
|
||
} | ||
|
||
module.exports = function getRuleFinder(specifiedFile) { | ||
return new RuleFinder(specifiedFile) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./eslint.yml", | ||
"plugins": [ | ||
"react" | ||
] | ||
} |
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,5 @@ | ||
extends: | ||
./eslintrc | ||
rules: | ||
bar-rule: | ||
- 2 |
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,5 @@ | ||
{ | ||
"rules": { | ||
"foo-rule": [2] | ||
} | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module.exports = { | ||
rules: { | ||
'no-alert': [2], | ||
}, | ||
'foo-rule': [2] | ||
} | ||
} |
Oops, something went wrong.