Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-find-rules

Package Overview
Dependencies
Maintainers
3
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-find-rules - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

test/fixtures/eslint-with-deprecated-rules.json

3

dist/bin/find.js

@@ -11,2 +11,3 @@ #!/usr/bin/env node

getUnusedRules: ['unused', 'u'],
getDeprecatedRules: ['deprecated', 'd'],
n: [],

@@ -36,3 +37,3 @@ error: ['error'],

if (!argv.c && !argv.p && !argv.a && !argv.u) {
if (!argv.c && !argv.p && !argv.a && !argv.u && !argv.d) {
console.log('no option provided, please provide a valid option'); // eslint-disable-line no-console

@@ -39,0 +40,0 @@ console.log('usage:'); // eslint-disable-line no-console

@@ -33,3 +33,3 @@ 'use strict';

function _getCurrentRules(config) {
function _getCurrentNamesRules(config) {
return Object.keys(config.rules);

@@ -56,9 +56,11 @@ }

function _isDeprecated(rule) {
return rule.meta && rule.meta.deprecated;
return rule && rule.meta && rule.meta.deprecated;
}
function _getPluginRules(config, _ref) {
var includeDeprecated = _ref.includeDeprecated;
function _notDeprecated(rule) {
return !_isDeprecated(rule);
}
var pluginRules = [];
function _getPluginRules(config) {
var pluginRules = new Map();
var plugins = config.plugins;

@@ -69,9 +71,7 @@ if (plugins) {

var pluginConfig = require(normalized.module); // eslint-disable-line import/no-dynamic-require
var rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules;
var rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules;
pluginRules = pluginRules.concat(Object.keys(rules).filter(function (rule) {
return includeDeprecated || !_isDeprecated(rules[rule]);
}).map(function (rule) {
return normalized.prefix + '/' + rule;
}));
Object.keys(rules).forEach(function (ruleName) {
return pluginRules.set(normalized.prefix + '/' + ruleName, rules[ruleName]);
});
});

@@ -82,8 +82,9 @@ }

function _getCoreRules(_ref2) {
var includeDeprecated = _ref2.includeDeprecated;
function _getCoreRules() {
return eslint.linter.getRules();
}
var rules = eslint.linter.getRules();
return Array.from(rules.keys()).filter(function (rule) {
return includeDeprecated || !_isDeprecated(rules.get(rule));
function _filterRuleNames(ruleNames, rules, predicate) {
return ruleNames.filter(function (ruleName) {
return predicate(rules.get(ruleName));
});

@@ -102,15 +103,24 @@ }

var config = _getConfig(configFile);
var currentRules = _getCurrentRules(config);
var pluginRules = _getPluginRules(config, { includeDeprecated: includeDeprecated });
var coreRules = _getCoreRules({ includeDeprecated: includeDeprecated });
var allRules = omitCore ? pluginRules : [].concat(_toConsumableArray(coreRules), _toConsumableArray(pluginRules));
var dedupedRules = [].concat(_toConsumableArray(new Set(allRules)));
var currentRuleNames = _getCurrentNamesRules(config);
if (omitCore) {
currentRules = currentRules.filter(_isNotCore);
currentRuleNames = currentRuleNames.filter(_isNotCore);
}
var unusedRules = difference(dedupedRules, currentRules); // eslint-disable-line vars-on-top
var pluginRules = _getPluginRules(config); // eslint-disable-line vars-on-top
var coreRules = _getCoreRules();
var allRules = omitCore ? pluginRules : new Map([].concat(_toConsumableArray(coreRules), _toConsumableArray(pluginRules)));
var allRuleNames = [].concat(_toConsumableArray(allRules.keys()));
var pluginRuleNames = [].concat(_toConsumableArray(pluginRules.keys()));
if (!includeDeprecated) {
allRuleNames = _filterRuleNames(allRuleNames, allRules, _notDeprecated);
pluginRuleNames = _filterRuleNames(pluginRuleNames, pluginRules, _notDeprecated);
}
var deprecatedRuleNames = _filterRuleNames(currentRuleNames, allRules, _isDeprecated);
var dedupedRuleNames = [].concat(_toConsumableArray(new Set(allRuleNames)));
var unusedRuleNames = difference(dedupedRuleNames, currentRuleNames);
// Get all the current rules instead of referring the extended files or documentation
this.getCurrentRules = function () {
return getSortedRules(currentRules);
return getSortedRules(currentRuleNames);
};

@@ -125,3 +135,3 @@

this.getPluginRules = function () {
return getSortedRules(pluginRules);
return getSortedRules(pluginRuleNames);
};

@@ -131,8 +141,13 @@

this.getAllAvailableRules = function () {
return getSortedRules(dedupedRules);
return getSortedRules(dedupedRuleNames);
};
this.getUnusedRules = function () {
return getSortedRules(unusedRules);
return getSortedRules(unusedRuleNames);
};
// Get all the current rules that are deprecated
this.getDeprecatedRules = function () {
return getSortedRules(deprecatedRuleNames);
};
}

@@ -139,0 +154,0 @@

{
"name": "eslint-find-rules",
"version": "3.1.1",
"version": "3.2.0",
"description": "Find built-in ESLint rules you don't have in your custom config.",

@@ -5,0 +5,0 @@ "main": "dist/lib/rule-finder.js",

@@ -48,10 +48,10 @@ # eslint-find-rules

```
available options are -c|--current, -a|--all-available, -p|--plugin, -u|--unused
available options are -a|--all-available, -c|--current, -d|--deprecated, -p|--plugin, -u|--unused
available flags are -n|--no-error, --no-core, and -i/--include deprecated
```
By default it will error out only for `-u|--unused`,
however if you do not want the `process` to `exit` with a `non-zero` exit code, use the `-n|--no-error` flag along with `-u|--unused`.
By default it will error out only for `-d|--deprecated` and `-u|--unused`,
however if you do not want the `process` to `exit` with a `non-zero` exit code, use the `-n|--no-error` flag along with `-d|--deprecated` or `-u|--unused`.
By default, core rules will be included in the output of `-c|--current`, `-a|--all-available`, and `-u|--unused`. If you want to report on plugin rules only, use the `--no-core` flag.
By default, core rules will be included in the output of `-a|--all-available`, `-c|--current`, `-d|--deprecated`, and `-u|--unused`. If you want to report on plugin rules only, use the `--no-core` flag.

@@ -67,3 +67,3 @@ By default, deprecated rules will be omitted from the output of `-a|--all-available`, `-p|--plugin` and `-u|--unused`. If you want to report on deprecated rules as well, use the `--include=deprecated` or `-i deprecated` flag.

```
// available options are -c|--current, -a|--all-available, -p|--plugin, -u|--unused
// available options are -a|--all-available, -c|--current, -d|--deprecated, -p|--plugin, -u|--unused
eslint-find-rules --option ./index.js

@@ -115,2 +115,4 @@ ```

ruleFinder.getUnusedRules()
ruleFinder.getDeprecatedRules()
```

@@ -117,0 +119,0 @@

@@ -9,2 +9,3 @@ #!/usr/bin/env node

getUnusedRules: ['unused', 'u'],
getDeprecatedRules: ['deprecated', 'd'],
n: [],

@@ -40,3 +41,3 @@ error: ['error'],

if (!argv.c && !argv.p && !argv.a && !argv.u) {
if (!argv.c && !argv.p && !argv.a && !argv.u && !argv.d) {
console.log('no option provided, please provide a valid option'); // eslint-disable-line no-console

@@ -43,0 +44,0 @@ console.log('usage:'); // eslint-disable-line no-console

@@ -29,3 +29,3 @@ const path = require('path');

function _getCurrentRules(config) {
function _getCurrentNamesRules(config) {
return Object.keys(config.rules);

@@ -52,7 +52,11 @@ }

function _isDeprecated(rule) {
return rule.meta && rule.meta.deprecated;
return rule && rule.meta && rule.meta.deprecated;
}
function _getPluginRules(config, {includeDeprecated}) {
let pluginRules = [];
function _notDeprecated(rule) {
return !_isDeprecated(rule);
}
function _getPluginRules(config) {
const pluginRules = new Map();
const plugins = config.plugins;

@@ -63,8 +67,6 @@ if (plugins) {

const pluginConfig = require(normalized.module); // eslint-disable-line import/no-dynamic-require
const rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules;
const rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules;
pluginRules = pluginRules.concat(
Object.keys(rules)
.filter(rule => includeDeprecated || !_isDeprecated(rules[rule]))
.map(rule => `${normalized.prefix}/${rule}`)
Object.keys(rules).forEach(ruleName =>
pluginRules.set(`${normalized.prefix}/${ruleName}`, rules[ruleName])
);

@@ -76,8 +78,10 @@ });

function _getCoreRules({includeDeprecated}) {
const rules = eslint.linter.getRules();
return Array.from(rules.keys())
.filter(rule => includeDeprecated || !_isDeprecated(rules.get(rule)));
function _getCoreRules() {
return eslint.linter.getRules();
}
function _filterRuleNames(ruleNames, rules, predicate) {
return ruleNames.filter(ruleName => predicate(rules.get(ruleName)));
}
function _isNotCore(rule) {

@@ -91,14 +95,23 @@ return rule.indexOf('/') !== '-1';

const config = _getConfig(configFile);
let currentRules = _getCurrentRules(config);
const pluginRules = _getPluginRules(config, {includeDeprecated});
const coreRules = _getCoreRules({includeDeprecated});
const allRules = omitCore ? pluginRules : [...coreRules, ...pluginRules];
const dedupedRules = [...new Set(allRules)];
let currentRuleNames = _getCurrentNamesRules(config);
if (omitCore) {
currentRules = currentRules.filter(_isNotCore);
currentRuleNames = currentRuleNames.filter(_isNotCore);
}
const unusedRules = difference(dedupedRules, currentRules); // eslint-disable-line vars-on-top
const pluginRules = _getPluginRules(config); // eslint-disable-line vars-on-top
const coreRules = _getCoreRules();
const allRules = omitCore ? pluginRules : new Map([...coreRules, ...pluginRules]);
let allRuleNames = [...allRules.keys()];
let pluginRuleNames = [...pluginRules.keys()];
if (!includeDeprecated) {
allRuleNames = _filterRuleNames(allRuleNames, allRules, _notDeprecated);
pluginRuleNames = _filterRuleNames(pluginRuleNames, pluginRules, _notDeprecated);
}
const deprecatedRuleNames = _filterRuleNames(currentRuleNames, allRules, _isDeprecated);
const dedupedRuleNames = [...new Set(allRuleNames)];
const unusedRuleNames = difference(dedupedRuleNames, currentRuleNames);
// Get all the current rules instead of referring the extended files or documentation
this.getCurrentRules = () => getSortedRules(currentRules);
this.getCurrentRules = () => getSortedRules(currentRuleNames);

@@ -109,8 +122,11 @@ // Get all the current rules' particular configuration

// Get all the plugin rules instead of referring the extended files or documentation
this.getPluginRules = () => getSortedRules(pluginRules);
this.getPluginRules = () => getSortedRules(pluginRuleNames);
// Get all the available rules instead of referring eslint and plugin packages or documentation
this.getAllAvailableRules = () => getSortedRules(dedupedRules);
this.getAllAvailableRules = () => getSortedRules(dedupedRuleNames);
this.getUnusedRules = () => getSortedRules(unusedRules);
this.getUnusedRules = () => getSortedRules(unusedRuleNames);
// Get all the current rules that are deprecated
this.getDeprecatedRules = () => getSortedRules(deprecatedRuleNames);
}

@@ -117,0 +133,0 @@

@@ -12,2 +12,3 @@ const assert = require('assert');

const getUnusedRules = sinon.stub().returns(['unused', 'rules']);
const getDeprecatedRules = sinon.stub().returns(['deprecated', 'rules']);

@@ -24,3 +25,4 @@ let stub;

getAllAvailableRules,
getUnusedRules
getUnusedRules,
getDeprecatedRules
};

@@ -31,3 +33,3 @@ }

console.log = (...args) => { // eslint-disable-line no-console
if (args[0].match(/(current|plugin|all-available|unused|rules found)/)) {
if (args[0].match(/(current|plugin|all-available|unused|deprecated|rules found)/)) {
return;

@@ -123,2 +125,41 @@ }

it('option -d|--deprecated', () => {
process.exit = status => {
assert.equal(status, 1);
};
process.argv[2] = '-d';
proxyquire('../../src/bin/find', stub);
assert.ok(getDeprecatedRules.called);
});
it('options -d|--deprecated and no deprecated rules found', () => {
getDeprecatedRules.returns([]);
process.exit = status => {
assert.equal(status, 0);
};
process.argv[2] = '-d';
proxyquire('../../src/bin/find', stub);
assert.ok(getDeprecatedRules.called);
});
it('option -d|--deprecated along with -n', () => {
process.exit = status => {
assert.equal(status, 0);
};
process.argv[2] = '-d';
process.argv[3] = '-n';
proxyquire('../../src/bin/find', stub);
assert.ok(getDeprecatedRules.called);
});
it('option -d|--deprecated along with --no-error', () => {
process.exit = status => {
assert.equal(status, 0);
};
process.argv[2] = '-d';
process.argv[3] = '--no-error';
proxyquire('../../src/bin/find', stub);
assert.ok(getDeprecatedRules.called);
});
it('logs verbosely', () => {

@@ -125,0 +166,0 @@ process.argv[2] = '-c';

@@ -72,2 +72,3 @@ const path = require('path');

const noDuplicateRulesFiles = './test/fixtures/eslint-dedupe-plugin-rules.json';
const usingDeprecatedRulesFile = path.join(process.cwd(), './test/fixtures/eslint-with-deprecated-rules.json');

@@ -383,2 +384,16 @@ describe('rule-finder', () => {

});
it('specifiedFile (absolute path) without deprecated rules - deprecated rules', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(ruleFinder.getDeprecatedRules(), []);
});
it('specifiedFile (absolute path) with deprecated rules - deprecated rules', () => {
const ruleFinder = getRuleFinder(usingDeprecatedRulesFile);
assert.deepEqual(ruleFinder.getDeprecatedRules(), [
'old-rule',
'plugin/old-plugin-rule',
'scoped-plugin/old-plugin-rule'
]);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc