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 1.14.3 to 2.0.0

51

package.json
{
"name": "eslint-find-rules",
"version": "1.14.3",
"version": "2.0.0",
"description": "Find built-in ESLint rules you don't have in your custom config.",
"main": "src/lib/rule-finder.js",
"main": "dist/lib/rule-finder.js",
"scripts": {
"cover": "nyc --reporter=lcov --reporter=text npm test",
"lint": "xo",
"test": "mocha --recursive",
"lint": "eslint --ignore-pattern test/fixtures .",
"update-contributors": "all-contributors generate",

@@ -14,9 +14,11 @@ "commit": "git-cz",

"check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"prebuild": "rimraf dist",
"build": "babel src -d dist --presets es2015",
"report-coverage": "cat ./coverage/lcov.info | node_modules/.bin/codecov",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"travis-after-all": "travis-after-all && npm run report-coverage && npm run semantic-release"
"travis-after-all": "travis-after-all && npm run report-coverage"
},
"bin": {
"eslint-find-rules": "src/bin/find.js",
"eslint-diff-rules": "src/bin/diff.js"
"eslint-find-rules": "dist/bin/find.js",
"eslint-diff-rules": "dist/bin/diff.js"
},

@@ -41,7 +43,9 @@ "keywords": [],

"all-contributors-cli": "3.0.6",
"babel-cli": "6.18.0",
"babel-core": "6.18.0",
"babel-preset-es2015": "6.18.0",
"codecov": "1.0.1",
"commitizen": "2.8.6",
"cz-conventional-changelog": "1.2.0",
"eslint": "3.5.0",
"eslint-config-kentcdodds": "6.2.0",
"eslint": "3.12.0",
"ghooks": "1.3.2",

@@ -53,24 +57,12 @@ "mocha": "^3.0.1",

"proxyquire": "1.7.10",
"rimraf": "^2.6.0",
"semantic-release": "4.3.5",
"sinon": "^1.17.3",
"travis-after-all": "^1.4.4",
"validate-commit-msg": "2.8.0"
"validate-commit-msg": "2.8.0",
"xo": "^0.17.0"
},
"peerDependencies": {
"eslint": "^2.0.0 || ^3.0.0"
"eslint": "^3.12.0"
},
"eslintConfig": {
"extends": "kentcdodds",
"parserOptions": {
"ecmaVersion": 5
},
"env": {
"mocha": true
},
"rules": {
"no-var": 0,
"func-names": 0,
"object-shorthand": 0
}
},
"nyc": {

@@ -97,3 +89,10 @@ "exclude": [

},
"homepage": "https://github.com/sarbbottam/eslint-find-rules#readme"
}
"homepage": "https://github.com/sarbbottam/eslint-find-rules#readme",
"xo": {
"envs": [
"mocha"
],
"esnext": true,
"space": true
}
}

@@ -16,3 +16,3 @@ # eslint-find-rules

## Acknowledgement
## Acknowledgment

@@ -19,0 +19,0 @@ This module is an extended version of [eslint-find-new-rules](https://github.com/kentcdodds/eslint-find-new-rules)

#!/usr/bin/env node
'use strict'
'use strict';
var path = require('path')
var argv = require('yargs')
const path = require('path');
const argv = require('yargs')
.boolean('verbose')
.alias('v', 'verbose')
.argv
.argv;
var cli = require('../lib/cli-util')
const cli = require('../lib/cli-util');
var getRuleFinder = require('../lib/rule-finder')
var arrayDifference = require('../lib/array-diff')
var objectDifference = require('../lib/object-diff')
var getSortedRules = require('../lib/sort-rules')
var flattenRulesDiff = require('../lib/flatten-rules-diff')
var stringifyRuleConfig = require('../lib/stringify-rule-config')
const getRuleFinder = require('../lib/rule-finder');
const arrayDifference = require('../lib/array-diff');
const objectDifference = require('../lib/object-diff');
const getSortedRules = require('../lib/sort-rules');
const flattenRulesDiff = require('../lib/flatten-rules-diff');
const stringifyRuleConfig = require('../lib/stringify-rule-config');
var files = [argv._[0], argv._[1]]
var collectedRules = getFilesToCompare(files).map(compareConfigs)
const files = [argv._[0], argv._[1]];
const collectedRules = getFilesToCompare(files).map(compareConfigs);
var rulesCount = collectedRules.reduce(
function getLength(prev, curr) {
return prev + (curr && curr.rules ? curr.rules.length : /* istanbul ignore next */ 0)
}, 0)
const rulesCount = collectedRules.reduce(
(prev, curr) => {
return prev + (curr && curr.rules ? curr.rules.length : /* istanbul ignore next */ 0);
}, 0);
/* istanbul ignore else */
if (argv.verbose || rulesCount) {
cli.push('\ndiff rules\n' + rulesCount + ' rules differ\n')
cli.push('\ndiff rules\n' + rulesCount + ' rules differ\n');
}

@@ -35,25 +35,25 @@

if (rulesCount) {
collectedRules.forEach(function displayConfigs(diff) {
var rules = diff.rules
collectedRules.forEach(diff => {
let rules = diff.rules;
/* istanbul ignore if */
if (!rules.length) {
return
if (rules.length < 1) {
return;
}
if (argv.verbose) {
rules = flattenRulesDiff(rules).map(stringifyRuleConfig)
rules.unshift([], diff.config1, diff.config2)
rules = flattenRulesDiff(rules).map(stringifyRuleConfig);
rules.unshift([], diff.config1, diff.config2);
} else {
cli.push('\nin ' + diff.config1 + ' but not in ' + diff.config2 + ':\n')
cli.push('\nin ' + diff.config1 + ' but not in ' + diff.config2 + ':\n');
}
cli.push(rules, argv.verbose ? 3 : 0)
})
cli.push(rules, argv.verbose ? 3 : 0);
});
}
cli.write()
cli.write();
function getFilesToCompare(allFiles) {
var filesToCompare = [allFiles]
const filesToCompare = [allFiles];

@@ -64,6 +64,6 @@ if (!argv.verbose) {

// accross those files, but grouped
filesToCompare.push([].concat(allFiles).reverse())
filesToCompare.push([].concat(allFiles).reverse());
}
return filesToCompare
return filesToCompare;
}

@@ -78,4 +78,4 @@

getRuleFinder(currentFiles[1])
),
}
)
};
}

@@ -90,3 +90,3 @@

)
)
);
}

@@ -99,3 +99,3 @@

)
)
);
}
#!/usr/bin/env node
'use strict'
var options = {
'use strict';
const options = {
getCurrentRules: ['current', 'c'],

@@ -14,6 +13,6 @@ getPluginRules: ['plugin', 'p'],

core: ['core'],
verbose: ['verbose', 'v'],
}
verbose: ['verbose', 'v']
};
var argv = require('yargs')
const argv = require('yargs')
.boolean(Object.keys(options))

@@ -23,50 +22,47 @@ .alias(options)

.default('core', true)
.argv
.argv;
var getRuleURI = require('eslint-rule-documentation')
const getRuleURI = require('eslint-rule-documentation');
const getRuleFinder = require('../lib/rule-finder');
const cli = require('../lib/cli-util');
var cli = require('../lib/cli-util')
const specifiedFile = argv._[0];
const ruleFinder = getRuleFinder(specifiedFile, argv.core === false);
const errorOut = argv.error && !argv.n;
let processExitCode = argv.u && errorOut ? 1 : 0;
var getRuleFinder = require('../lib/rule-finder')
var specifiedFile = argv._[0]
var ruleFinder = getRuleFinder(specifiedFile, argv.core === false)
var errorOut = argv.error && !argv.n
var processExitCode = argv.u && errorOut ? 1 : 0
if (!argv.c && !argv.p && !argv.a && !argv.u) {
console.log('no option provided, please provide a valid option') // eslint-disable-line no-console
console.log('usage:') // eslint-disable-line no-console
console.log('eslint-find-rules [option] <file> [flag]') // eslint-disable-line no-console
process.exit(0)
console.log('no option provided, please provide a valid option'); // eslint-disable-line no-console
console.log('usage:'); // eslint-disable-line no-console
console.log('eslint-find-rules [option] <file> [flag]'); // eslint-disable-line no-console
process.exit(0);
}
Object.keys(options).forEach(function findRules(option) {
var rules
var ruleFinderMethod = ruleFinder[option]
Object.keys(options).forEach(option => {
let rules;
const ruleFinderMethod = ruleFinder[option];
if (argv[option] && ruleFinderMethod) {
rules = ruleFinderMethod()
argv.verbose && cli.push('\n' + options[option][0] + ' rules\n' + rules.length + ' rules found\n')
if (rules.length) {
rules = ruleFinderMethod();
if (argv.verbose) {
cli.push('\n' + options[option][0] + ' rules\n' + rules.length + ' rules found\n');
}
if (rules.length > 0) {
if (argv.verbose) {
rules = rules.map(function(rule) {
return [rule, getRuleURI(rule).url]
}).reduce(function(all, single) {
return all.concat(single)
})
cli.push(rules, 2, false)
rules = rules
.map(rule => [rule, getRuleURI(rule).url])
.reduce((all, single) => all.concat(single));
cli.push(rules, 2, false);
} else {
cli.push('\n' + options[option][0] + ' rules\n')
cli.push(rules)
cli.push('\n' + options[option][0] + ' rules\n');
cli.push(rules);
}
cli.write()
cli.write();
} else /* istanbul ignore else */ if (option === 'getUnusedRules') {
processExitCode = 0
processExitCode = 0;
}
}
})
});
if (processExitCode) {
process.exit(processExitCode)
process.exit(processExitCode);
}
function difference(a, b) {
var hash = {}
var diff = {}
b.forEach(function createHash(item) {
hash[item] = true
})
a.forEach(function findDiff(item) {
if (!hash[item] && !diff[item]) {
diff[item] = true
}
})
return Object.keys(diff)
return a.filter(item => !b.includes(item)).sort((a, b) => a > b);
}
module.exports = difference
module.exports = difference;

@@ -1,33 +0,31 @@

var size = require('window-size')
var availableWidth = size.width || /*istanbul ignore next */ 80
var ui = require('cliui')({width: availableWidth})
const size = require('window-size');
const availableWidth = size.width || /* istanbul ignore next */ 80;
const ui = require('cliui')({width: availableWidth});
function push(output, columns, uniformColWidths) {
var _output = [].concat(output)
const _output = [].concat(output);
var padding = {top: 0, right: 2, bottom: 0, left: 0}
var maxWidth = [_output.reduce(
function getMaxWidth(previous, current) {
return Math.max(padding.left + current.length + padding.right, previous)
}, 0)]
const padding = {top: 0, right: 2, bottom: 0, left: 0};
const maxWidth = [_output.reduce((previous, current) => Math.max(padding.left + current.length + padding.right, previous), 0)];
var _columns = columns || Math.floor(availableWidth / maxWidth)
var cellMapper, widths
const _columns = columns || Math.floor(availableWidth / maxWidth);
let widths;
if (uniformColWidths === false && _columns > 1) {
widths = []
_output.forEach(function(content, index) {
widths = [];
_output.forEach((content, index) => {
widths[index % _columns] = Math.max(
padding.left + content.length + padding.right,
widths[index % _columns] || 0
)
})
);
});
} else {
widths = [Math.floor(availableWidth / _columns)]
widths = [Math.floor(availableWidth / _columns)];
}
cellMapper = getOutputCellMapper(widths, padding)
const cellMapper = getOutputCellMapper(widths, padding);
while (_output.length) {
ui.div.apply(ui, _output.splice(0, _columns).map(cellMapper))
ui.div(..._output.splice(0, _columns).map(cellMapper));
}

@@ -37,24 +35,24 @@ }

function write(logger) {
var _logger = logger || console
var _log = _logger.log || /* istanbul ignore next */ console.log // eslint-disable-line no-console
_log(ui.toString())
const _logger = logger || console;
const _log = _logger.log || /* istanbul ignore next */ console.log; // eslint-disable-line no-console
_log(ui.toString());
}
function getOutputCellMapper(widths, padding) {
return function curriedOutputCellMapper(text, index) {
var _width = widths[index]
return (text, index) => {
let _width = widths[index];
if (_width === undefined) {
_width = widths[0]
_width = widths[0];
}
return {
text: text,
text,
width: _width,
padding: [padding.top, padding.right, padding.bottom, padding.left],
}
}
padding: [padding.top, padding.right, padding.bottom, padding.left]
};
};
}
module.exports = {
push: push,
write: write,
}
push,
write
};
function flattenRulesDiff(diff) {
if (Array.isArray(diff)) {
return flattenRulesDiffArray(diff)
return flattenRulesDiffArray(diff);
} else if (typeof diff === 'object') {
return flattenRulesDiffObject(diff)
return flattenRulesDiffObject(diff);
}
return []
return [];
}
function flattenRulesDiffObject(diffObject) {
var flattened = []
const flattened = [];
Object.keys(diffObject).forEach(function flattenEachRuleDiff(ruleName) {
var ruleRow = [ruleName]
var diff = diffObject[ruleName]
Object.keys(diffObject).forEach(ruleName => {
const diff = diffObject[ruleName];
const ruleRow = [ruleName].concat(
Object.keys(diff).map(configName => diff[configName])
);
Object.keys(diff).forEach(function flattenEachChildProp(configName) {
ruleRow.push(diff[configName])
})
flattened.push(...ruleRow);
});
flattened.push.apply(flattened, ruleRow)
})
return flattened
return flattened;
}
function flattenRulesDiffArray(diffArray) {
var flattened = []
const flattened = [];
diffArray.forEach(function flattenEachDiff(diff) {
flattened.push.apply(flattened, flattenRulesDiff(diff))
})
diffArray.forEach(diff => {
flattened.push(...flattenRulesDiff(diff));
});
return flattened
return flattened;
}
module.exports = flattenRulesDiff
module.exports = flattenRulesDiff;

@@ -1,27 +0,27 @@

var assert = require('assert')
const assert = require('assert');
function difference(a, b) {
var diff = {}
const diff = {};
Object.keys(a).forEach(compare(diff, a, b))
Object.keys(b).forEach(compare(diff, a, b))
Object.keys(a).forEach(compare(diff, a, b));
Object.keys(b).forEach(compare(diff, a, b));
return diff
return diff;
}
function compare(diff, a, b) {
return function curried(n) {
return n => {
if (!diff[n]) {
try {
assert.deepEqual(a[n], b[n])
} catch (e) {
assert.deepEqual(a[n], b[n]);
} catch (err) {
diff[n] = {
config1: a[n],
config2: b[n],
}
config2: b[n]
};
}
}
}
};
}
module.exports = difference
module.exports = difference;

@@ -1,8 +0,7 @@

var path = require('path')
var fs = require('fs')
const path = require('path');
var eslint = require('eslint')
var isAbsolute = require('path-is-absolute')
var difference = require('./array-diff')
var getSortedRules = require('./sort-rules')
const eslint = require('eslint');
const isAbsolute = require('path-is-absolute');
const difference = require('./array-diff');
const getSortedRules = require('./sort-rules');

@@ -12,120 +11,99 @@ function _getConfigFile(specifiedFile) {

if (isAbsolute(specifiedFile)) {
return specifiedFile
} else {
return path.join(process.cwd(), specifiedFile)
return specifiedFile;
}
} else {
// this is not being called with an arg. Use the package.json `main`
return require(path.join(process.cwd(), 'package.json')).main
return path.join(process.cwd(), specifiedFile); // eslint-disable-line import/no-dynamic-require
}
// this is not being called with an arg. Use the package.json `main`
return require(path.join(process.cwd(), 'package.json')).main; // eslint-disable-line import/no-dynamic-require
}
function _getConfig(configFile) {
var cliEngine = new eslint.CLIEngine({
const 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()
configFile
});
return cliEngine.getConfigForFile();
}
function _getCurrentRules(config) {
return Object.keys(config.rules)
return Object.keys(config.rules);
}
function _normalizePluginName(name) {
var scopedRegex = /(@[^/]+)\/(.+)/
var match = scopedRegex.exec(name)
const scopedRegex = /(@[^/]+)\/(.+)/;
const match = scopedRegex.exec(name);
if (match) {
return {
module: match[1] + '/' + 'eslint-plugin-' + match[2],
prefix: match[2],
}
module: `${match[1]}/eslint-plugin-${match[2]}`,
prefix: match[2]
};
}
return {
module: 'eslint-plugin-' + name,
prefix: name,
}
module: `eslint-plugin-${name}`,
prefix: name
};
}
function _getPluginRules(config) {
var pluginRules = []
var plugins = config.plugins
let pluginRules = [];
const plugins = config.plugins;
if (plugins) {
plugins.forEach(function getPluginRule(plugin) {
var normalized = _normalizePluginName(plugin)
var pluginConfig = require(normalized.module)
plugins.forEach(plugin => {
const normalized = _normalizePluginName(plugin);
const pluginConfig = require(normalized.module); // eslint-disable-line import/no-dynamic-require
var rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules
const rules = pluginConfig.rules === undefined ? {} : pluginConfig.rules;
pluginRules = pluginRules.concat(
Object.keys(rules).map(function normalizePluginRule(rule) {
return normalized.prefix + '/' + rule
Object.keys(rules).map(rule => {
return normalized.prefix + '/' + rule;
})
)
})
);
});
}
return pluginRules
return pluginRules;
}
function _getAllAvailableRules(pluginRules) {
var allRules = fs
.readdirSync('./node_modules/eslint/lib/rules')
var filteredAllRules = []
allRules.forEach(function filterAllRules(filename) {
if (filename.slice(-3) === '.js') {
filteredAllRules.push(filename.replace(/\.js$/, ''))
}
})
filteredAllRules = filteredAllRules.concat(pluginRules)
return filteredAllRules
return [
...eslint.linter.getRules().keys(),
...pluginRules
];
}
function _isNotCore(rule) {
return rule.indexOf('/') !== '-1'
return rule.indexOf('/') !== '-1';
}
function RuleFinder(specifiedFile, noCore) {
var configFile = _getConfigFile(specifiedFile)
var config = _getConfig(configFile)
var currentRules = _getCurrentRules(config)
var pluginRules = _getPluginRules(config)
var allRules = noCore ? pluginRules : _getAllAvailableRules(pluginRules)
const configFile = _getConfigFile(specifiedFile);
const config = _getConfig(configFile);
let currentRules = _getCurrentRules(config);
const pluginRules = _getPluginRules(config);
const allRules = noCore ? pluginRules : _getAllAvailableRules(pluginRules);
if (noCore) {
currentRules = currentRules.filter(_isNotCore)
currentRules = currentRules.filter(_isNotCore);
}
var unusedRules = difference(allRules, currentRules) // eslint-disable-line vars-on-top
const unusedRules = difference(allRules, currentRules); // eslint-disable-line vars-on-top
// get all the current rules instead of referring the extended files or documentation
this.getCurrentRules = function getCurrentRules() {
return getSortedRules(currentRules)
}
this.getCurrentRules = () => getSortedRules(currentRules);
// get all the current rules' particular configuration
this.getCurrentRulesDetailed = function getCurrentRulesDetailed() {
return config.rules
}
this.getCurrentRulesDetailed = () => config.rules;
// get all the plugin rules instead of referring the extended files or documentation
this.getPluginRules = function getPluginRules() {
return getSortedRules(pluginRules)
}
this.getPluginRules = () => getSortedRules(pluginRules);
// get all the available rules instead of referring eslint and plugin packages or documentation
this.getAllAvailableRules = function getAllAvailableRules() {
return getSortedRules(allRules)
}
this.getAllAvailableRules = () => getSortedRules(allRules);
this.getUnusedRules = function getUnusedRules() {
return getSortedRules(unusedRules)
}
this.getUnusedRules = () => getSortedRules(unusedRules);
}
module.exports = function getRuleFinder(specifiedFile, noCore) {
return new RuleFinder(specifiedFile, noCore)
}
module.exports = function (specifiedFile, noCore) {
return new RuleFinder(specifiedFile, noCore);
};

@@ -1,29 +0,29 @@

'use strict'
'use strict';
function getSortedRules(rules) {
return Array.isArray(rules) ? getSortedRulesArray(rules) : transformIntoSortedRulesArray(rules)
return Array.isArray(rules) ? getSortedRulesArray(rules) : transformIntoSortedRulesArray(rules);
}
function getSortedRulesArray(rules) {
return rules.sort(sortAlphabetically)
return rules.sort(sortAlphabetically);
}
function transformIntoSortedRulesArray(rules) {
var sortedRules = []
const sortedRules = [];
Object.keys(rules)
.sort(sortAlphabetically)
.forEach(function mapRules(ruleName) {
var rule = {}
rule[ruleName] = rules[ruleName]
sortedRules.push(rule)
})
.forEach(ruleName => {
const rule = {};
rule[ruleName] = rules[ruleName];
sortedRules.push(rule);
});
return sortedRules
return sortedRules;
}
function sortAlphabetically(a, b) {
return a > b ? 1 : -1
return a > b ? 1 : -1;
}
module.exports = getSortedRules
module.exports = getSortedRules;
function stringifyRuleConfig(rule) {
if (typeof rule === 'string') {
return rule
return rule;
} else if (typeof rule === 'undefined') {
return '-'
return '-';
}
return JSON.stringify(rule)
return JSON.stringify(rule);
}
module.exports = stringifyRuleConfig
module.exports = stringifyRuleConfig;

@@ -1,40 +0,39 @@

var assert = require('assert')
var proxyquire = require('proxyquire')
var sinon = require('sinon')
const assert = require('assert');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
var consoleLog = console.log // eslint-disable-line no-console
const consoleLog = console.log; // eslint-disable-line no-console
var stub = {
'../lib/rule-finder': function() {
const stub = {
'../lib/rule-finder'() {
return {
getCurrentRules: function noop() {},
getCurrentRulesDetailed: function noop() {},
}
getCurrentRules() {}, // noop
getCurrentRulesDetailed() {} // noop
};
},
'../lib/array-diff': sinon.stub().returns(['diff']),
'../lib/object-diff': sinon.stub().returns([{'test-rule': {config1: 'foo-config', config2: 'bar-config'}}]),
}
'../lib/object-diff': sinon.stub().returns([{'test-rule': {config1: 'foo-config', config2: 'bar-config'}}])
};
describe('diff', function() {
beforeEach(function() {
process.argv = process.argv.slice(0, 2)
sinon.stub(console, 'log', function() {
describe('diff', () => {
beforeEach(() => {
process.argv = process.argv.slice(0, 2);
sinon.stub(console, 'log', (...args) => {
// print out everything but the test target's output
if (!arguments[0].match(/diff/)) {
consoleLog.apply(null, arguments)
if (!args[0].match(/diff/)) {
consoleLog(...args);
}
})
})
});
});
afterEach(function() {
console.log.restore() // eslint-disable-line no-console
afterEach(() => {
console.log.restore(); // eslint-disable-line no-console
// purge yargs cache
delete require.cache[require.resolve('yargs')]
})
delete require.cache[require.resolve('yargs')];
});
it('logs diff', function() {
process.argv[2] = './foo'
process.argv[3] = './bar'
proxyquire('../../src/bin/diff', stub)
it('logs diff', () => {
process.argv[2] = './foo';
process.argv[3] = './bar';
proxyquire('../../src/bin/diff', stub);
assert.ok(

@@ -46,10 +45,10 @@ console.log.calledWith( // eslint-disable-line no-console

)
)
})
);
});
it('logs diff verbosely', function() {
process.argv[2] = '--verbose'
process.argv[3] = './foo'
process.argv[4] = './bar'
proxyquire('../../src/bin/diff', stub)
it('logs diff verbosely', () => {
process.argv[2] = '--verbose';
process.argv[3] = './foo';
process.argv[4] = './bar';
proxyquire('../../src/bin/diff', stub);
assert.ok(

@@ -61,4 +60,4 @@ console.log.calledWith( // eslint-disable-line no-console

)
)
})
})
);
});
});

@@ -1,151 +0,151 @@

var assert = require('assert')
var proxyquire = require('proxyquire')
var sinon = require('sinon')
const assert = require('assert');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
var consoleLog = console.log // eslint-disable-line no-console
var processExit = process.exit
const consoleLog = console.log; // eslint-disable-line no-console
const processExit = process.exit;
var getCurrentRules = sinon.stub().returns(['current', 'rules'])
var getPluginRules = sinon.stub().returns(['plugin', 'rules'])
var getAllAvailableRules = sinon.stub().returns(['all', 'available'])
var getUnusedRules = sinon.stub().returns(['unused', 'rules'])
const getCurrentRules = sinon.stub().returns(['current', 'rules']);
const getPluginRules = sinon.stub().returns(['plugin', 'rules']);
const getAllAvailableRules = sinon.stub().returns(['all', 'available']);
const getUnusedRules = sinon.stub().returns(['unused', 'rules']);
var stub
let stub;
describe('bin', function() {
beforeEach(function() {
describe('bin', () => {
beforeEach(() => {
stub = {
'../lib/rule-finder': function() {
'../lib/rule-finder'() {
return {
getCurrentRules: getCurrentRules,
getPluginRules: getPluginRules,
getAllAvailableRules: getAllAvailableRules,
getUnusedRules: getUnusedRules,
}
},
}
getCurrentRules,
getPluginRules,
getAllAvailableRules,
getUnusedRules
};
}
};
console.log = function() { // eslint-disable-line no-console
if (arguments[0].match(/(current|plugin|all\-available|unused|rules found)/)) {
return
console.log = (...args) => { // eslint-disable-line no-console
if (args[0].match(/(current|plugin|all-available|unused|rules found)/)) {
return;
}
consoleLog.apply(null, arguments)
}
process.exit = function noop() {}
process.argv = process.argv.slice(0, 2)
})
consoleLog(...args);
};
process.exit = function () {}; // noop
process.argv = process.argv.slice(0, 2);
});
afterEach(function() {
console.log = consoleLog // eslint-disable-line no-console
process.exit = processExit
afterEach(() => {
console.log = consoleLog; // eslint-disable-line no-console
process.exit = processExit;
// purge yargs cache
delete require.cache[require.resolve('yargs')]
})
delete require.cache[require.resolve('yargs')];
});
it('no option', function() {
var callCount = 0
console.log = function() { // eslint-disable-line no-console
callCount += 1
if (arguments[0].match(
/(no option provided, please provide a valid option|usage:|eslint-find-rules \[option\] <file> \[flag\])/)
it('no option', () => {
let callCount = 0;
console.log = (...args) => { // eslint-disable-line no-console
callCount += 1;
if (args[0].match(
/(no option provided, please provide a valid option|usage:|eslint-find-rules \[option] <file> \[flag])/)
) {
return
return;
}
consoleLog.apply(null, arguments)
}
proxyquire('../../src/bin/find', stub)
assert.equal(callCount, 3) // eslint-disable-line no-console
})
consoleLog(...args);
};
proxyquire('../../src/bin/find', stub);
assert.equal(callCount, 3); // eslint-disable-line no-console
});
it('option -c|--current', function() {
process.argv[2] = '-c'
proxyquire('../../src/bin/find', stub)
assert.ok(getCurrentRules.called)
})
it('option -c|--current', () => {
process.argv[2] = '-c';
proxyquire('../../src/bin/find', stub);
assert.ok(getCurrentRules.called);
});
it('option -p|--plugin', function() {
process.argv[2] = '-p'
proxyquire('../../src/bin/find', stub)
assert.ok(getPluginRules.called)
})
it('option -p|--plugin', () => {
process.argv[2] = '-p';
proxyquire('../../src/bin/find', stub);
assert.ok(getPluginRules.called);
});
it('option -a|--all-available', function() {
process.argv[2] = '-a'
proxyquire('../../src/bin/find', stub)
assert.ok(getAllAvailableRules.called)
process.argv[2] = '--all-available'
proxyquire('../../src/bin/find', stub)
assert.ok(getAllAvailableRules.called)
})
it('option -a|--all-available', () => {
process.argv[2] = '-a';
proxyquire('../../src/bin/find', stub);
assert.ok(getAllAvailableRules.called);
process.argv[2] = '--all-available';
proxyquire('../../src/bin/find', stub);
assert.ok(getAllAvailableRules.called);
});
it('option -u|--unused', function() {
process.exit = function(status) {
assert.equal(status, 1)
}
process.argv[2] = '-u'
proxyquire('../../src/bin/find', stub)
assert.ok(getUnusedRules.called)
})
it('option -u|--unused', () => {
process.exit = status => {
assert.equal(status, 1);
};
process.argv[2] = '-u';
proxyquire('../../src/bin/find', stub);
assert.ok(getUnusedRules.called);
});
it('options -u|--unused and no unused rules found', function() {
getUnusedRules.returns([])
process.exit = function(status) {
assert.equal(status, 0)
}
process.argv[2] = '-u'
proxyquire('../../src/bin/find', stub)
assert.ok(getUnusedRules.called)
})
it('options -u|--unused and no unused rules found', () => {
getUnusedRules.returns([]);
process.exit = status => {
assert.equal(status, 0);
};
process.argv[2] = '-u';
proxyquire('../../src/bin/find', stub);
assert.ok(getUnusedRules.called);
});
it('option -u|--unused along with -n|--no-error', function() {
process.exit = function(status) {
assert.equal(status, 0)
}
process.argv[2] = '-u'
process.argv[3] = '-n'
proxyquire('../../src/bin/find', stub)
assert.ok(getUnusedRules.called)
process.argv[2] = '-u'
process.argv[3] = '--no-error'
proxyquire('../../src/bin/find', stub)
assert.ok(getUnusedRules.called)
})
it('option -u|--unused along with -n|--no-error', () => {
process.exit = status => {
assert.equal(status, 0);
};
process.argv[2] = '-u';
process.argv[3] = '-n';
proxyquire('../../src/bin/find', stub);
assert.ok(getUnusedRules.called);
process.argv[2] = '-u';
process.argv[3] = '--no-error';
proxyquire('../../src/bin/find', stub);
assert.ok(getUnusedRules.called);
});
it('logs verbosely', function() {
process.argv[2] = '-c'
process.argv[3] = '-v'
proxyquire('../../src/bin/find', stub)
assert.ok(getCurrentRules.called)
})
it('logs verbosely', () => {
process.argv[2] = '-c';
process.argv[3] = '-v';
proxyquire('../../src/bin/find', stub);
assert.ok(getCurrentRules.called);
});
it('logs core rules', function() {
it('logs core rules', () => {
stub = {
'../lib/rule-finder': function(specifiedFile, noCore) {
'../lib/rule-finder'(specifiedFile, noCore) {
return {
getCurrentRules: function() {
assert(!noCore)
return ['current', 'rules']
},
}
},
}
process.argv[2] = '-c'
proxyquire('../../src/bin/find', stub)
})
getCurrentRules() {
assert(!noCore);
return ['current', 'rules'];
}
};
}
};
process.argv[2] = '-c';
proxyquire('../../src/bin/find', stub);
});
it('does not log core rules', function() {
it('does not log core rules', () => {
stub = {
'../lib/rule-finder': function(specifiedFile, noCore) {
'../lib/rule-finder'(specifiedFile, noCore) {
return {
getCurrentRules: function() {
assert(noCore)
return ['current', 'rules']
},
}
},
}
process.argv[2] = '-c'
process.argv[3] = '--no-core'
proxyquire('../../src/bin/find', stub)
})
})
getCurrentRules() {
assert(noCore);
return ['current', 'rules'];
}
};
}
};
process.argv[2] = '-c';
process.argv[3] = '--no-core';
proxyquire('../../src/bin/find', stub);
});
});

@@ -1,24 +0,23 @@

var assert = require('assert')
var difference = require('../../src/lib/array-diff')
const assert = require('assert');
const difference = require('../../src/lib/array-diff');
describe('array difference', function() {
it('should return difference', function() {
describe('array difference', () => {
it('should return difference', () => {
assert.deepEqual(
difference(['a', 'b', 'c'], ['x', 'y', 'z']),
['a', 'b', 'c']
)
);
assert.deepEqual(
difference(['a', 'b', 'c'], ['a', 'y', 'z']),
['b', 'c']
)
);
assert.deepEqual(
difference(['a', 'b', 'c'], ['a', 'b', 'z']),
['c']
)
);
assert.deepEqual(
difference(['a', 'b', 'c'], ['a', 'b', 'c']),
[]
)
})
})
);
});
});

@@ -1,29 +0,28 @@

var assert = require('assert')
var proxyquire = require('proxyquire')
var sinon = require('sinon')
const assert = require('assert');
const proxyquire = require('proxyquire');
const sinon = require('sinon');
var moduleStub = {
'window-size': {width: 80},
}
const moduleStub = {
'window-size': {width: 80}
};
var loggerStub = {
log: function noop() {},
}
const loggerStub = {
log() {} // noop
};
describe('cli-util', function() {
describe('cli-util', () => {
before(() => {
sinon.stub(loggerStub, 'log');
});
before(function() {
sinon.stub(loggerStub, 'log')
})
after(() => {
loggerStub.log.restore();
});
after(function() {
loggerStub.log.restore()
})
it('prints out single lines', () => {
const cli = proxyquire('../../src/lib/cli-util', moduleStub);
it('prints out single lines', function() {
var cli = proxyquire('../../src/lib/cli-util', moduleStub)
cli.push('A single line');
cli.write(loggerStub);
cli.push('A single line')
cli.write(loggerStub)
assert.ok(

@@ -33,7 +32,7 @@ loggerStub.log.calledWith(

)
)
})
);
});
it('prints out multiple columns', function() {
var cli = proxyquire('../../src/lib/cli-util', moduleStub)
it('prints out multiple columns', () => {
const cli = proxyquire('../../src/lib/cli-util', moduleStub);

@@ -45,5 +44,5 @@ cli.push([

'Everything in a single cell',
'Everything in a single cell',
])
cli.write(loggerStub)
'Everything in a single cell'
]);
cli.write(loggerStub);

@@ -54,7 +53,7 @@ assert.ok(

)
)
})
);
});
it('prints out with an exact amount of columns', function() {
var cli = proxyquire('../../src/lib/cli-util', moduleStub)
it('prints out with an exact amount of columns', () => {
const cli = proxyquire('../../src/lib/cli-util', moduleStub);

@@ -66,5 +65,5 @@ cli.push([

'This in the second row',
'This in the second row',
], 3)
cli.write(loggerStub)
'This in the second row'
], 3);
cli.write(loggerStub);

@@ -77,5 +76,4 @@ assert.ok(

)
)
})
})
);
});
});

@@ -1,38 +0,38 @@

var assert = require('assert')
var flattenRulesDiff = require('../../src/lib/flatten-rules-diff')
const assert = require('assert');
const flattenRulesDiff = require('../../src/lib/flatten-rules-diff');
describe('flatten rules diff', function() {
it('should return flat array from diff-object with single rule', function() {
describe('flatten rules diff', () => {
it('should return flat array from diff-object with single rule', () => {
assert.deepEqual(
flattenRulesDiff({'foo-rule': {config1: [2, 'foo'], config2: [2, 'bar']}}),
['foo-rule', [2, 'foo'], [2, 'bar']]
)
})
);
});
it('should return flat array from diff-object with multiple rules', function() {
it('should return flat array from diff-object with multiple rules', () => {
assert.deepEqual(
flattenRulesDiff({
'foo-rule': {config1: [2, 'foo'], config2: [2, 'bar']},
'bar-rule': {config1: undefined, config2: [1, 'bar']},
'bar-rule': {config1: undefined, config2: [1, 'bar']}
}),
['foo-rule', [2, 'foo'], [2, 'bar'], 'bar-rule', undefined, [1, 'bar']]
)
})
);
});
it('should return flat array from an array of diff-objects', function() {
it('should return flat array from an array of diff-objects', () => {
assert.deepEqual(
flattenRulesDiff([
{'foo-rule': {config1: [2, 'foo'], config2: [2, 'bar']}},
{'bar-rule': {config1: undefined, config2: [1, 'bar']}},
{'bar-rule': {config1: undefined, config2: [1, 'bar']}}
]),
['foo-rule', [2, 'foo'], [2, 'bar'], 'bar-rule', undefined, [1, 'bar']]
)
})
);
});
it('should return empty array on anything else', function() {
it('should return empty array on anything else', () => {
assert.deepEqual(
flattenRulesDiff(undefined),
[]
)
})
})
);
});
});

@@ -1,14 +0,14 @@

var assert = require('assert')
var difference = require('../../src/lib/object-diff')
const assert = require('assert');
const difference = require('../../src/lib/object-diff');
describe('object difference', function() {
it('should return difference', function() {
describe('object difference', () => {
it('should return difference', () => {
assert.deepEqual(
difference({'foo-rule': [2, 'foo']}, {'foo-rule': [2, 'bar']}),
{'foo-rule': {config1: [2, 'foo'], config2: [2, 'bar']}}
)
);
assert.deepEqual(
difference({'foo-rule': [2, 'foo', 'bar']}, {'foo-rule': 2}),
{'foo-rule': {config1: [2, 'foo', 'bar'], config2: 2}}
)
);
assert.deepEqual(

@@ -18,11 +18,10 @@ difference({'foo-rule': [0, 'foo']}, {'bar-rule': [1, 'bar']}),

'foo-rule': {config1: [0, 'foo'], config2: undefined},
'bar-rule': {config1: undefined, config2: [1, 'bar']},
'bar-rule': {config1: undefined, config2: [1, 'bar']}
}
)
);
assert.deepEqual(
difference({'foo-rule': [1, 'foo', 'bar']}, {'foo-rule': [1, 'foo', 'bar']}),
{}
)
})
})
);
});
});

@@ -1,12 +0,17 @@

var path = require('path')
var assert = require('assert')
var proxyquire = require('proxyquire')
const path = require('path');
const assert = require('assert');
const proxyquire = require('proxyquire');
var processCwd = process.cwd
const processCwd = process.cwd;
var getRuleFinder = proxyquire('../../src/lib/rule-finder', {
fs: {
readdirSync: function() {
return ['.eslintrc.yml', 'foo-rule.js', 'bar-rule.js', 'baz-rule.js']
},
const getRuleFinder = proxyquire('../../src/lib/rule-finder', {
eslint: {
linter: {
getRules() {
return new Map()
.set('foo-rule', {})
.set('bar-rule', {})
.set('baz-rule', {});
}
}
},

@@ -17,6 +22,6 @@ 'eslint-plugin-plugin': {

'bar-rule': true,
'baz-rule': true,
'baz-rule': true
},
'@noCallThru': true,
'@global': true,
'@global': true
},

@@ -26,3 +31,3 @@ 'eslint-plugin-no-rules': {

'@noCallThru': true,
'@global': true,
'@global': true
},

@@ -32,75 +37,69 @@ '@scope/eslint-plugin-scoped-plugin': {

'foo-rule': true,
'bar-rule': true,
'bar-rule': true
},
'@noCallThru': true,
'@global': true,
},
})
'@global': true
}
});
var noSpecifiedFile = path.resolve(process.cwd(), './test/fixtures/no-path')
var specifiedFileRelative = './test/fixtures/eslint.json'
var specifiedFileAbsolute = path.join(process.cwd(), specifiedFileRelative)
var noRulesFile = path.join(process.cwd(), './test/fixtures/eslint-with-plugin-with-no-rules.json')
const noSpecifiedFile = path.resolve(process.cwd(), './test/fixtures/no-path');
const specifiedFileRelative = './test/fixtures/eslint.json';
const specifiedFileAbsolute = path.join(process.cwd(), specifiedFileRelative);
const noRulesFile = path.join(process.cwd(), './test/fixtures/eslint-with-plugin-with-no-rules.json');
describe('rule-finder', function() {
afterEach(function() {
process.cwd = processCwd
})
describe('rule-finder', () => {
afterEach(() => {
process.cwd = processCwd;
});
it('no specifiedFile is passed to the constructor', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder()
assert.deepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule'])
})
it('no specifiedFile is passed to the constructor', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder();
assert.deepEqual(ruleFinder.getUnusedRules(), ['bar-rule', 'baz-rule']);
});
it('no specifiedFile - current rules', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder()
assert.deepEqual(ruleFinder.getCurrentRules(), ['foo-rule'])
})
it('no specifiedFile - current rules', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder();
assert.deepEqual(ruleFinder.getCurrentRules(), ['foo-rule']);
});
it('no specifiedFile - current rule config', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder()
assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), {'foo-rule': [2]})
})
it('no specifiedFile - current rule config', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder();
assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), {'foo-rule': [2]});
});
it('no specifiedFile - plugin rules', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder()
assert.deepEqual(ruleFinder.getPluginRules(), [])
})
it('no specifiedFile - plugin rules', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder();
assert.deepEqual(ruleFinder.getPluginRules(), []);
});
it('no specifiedFile - all available rules', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder()
assert.deepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule'])
})
it('no specifiedFile - all available rules', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder();
assert.deepEqual(ruleFinder.getAllAvailableRules(), ['bar-rule', 'baz-rule', 'foo-rule']);
});
it('no specifiedFile - all available rules without core', function() {
var ruleFinder
process.cwd = function() {
return noSpecifiedFile
}
ruleFinder = getRuleFinder(null, true)
assert.deepEqual(ruleFinder.getAllAvailableRules(), [])
})
it('no specifiedFile - all available rules without core', () => {
process.cwd = function () {
return noSpecifiedFile;
};
const ruleFinder = getRuleFinder(null, true);
assert.deepEqual(ruleFinder.getAllAvailableRules(), []);
});
it('specifiedFile (relative path) is passed to the constructor', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative)
it('specifiedFile (relative path) is passed to the constructor', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative);
assert.deepEqual(ruleFinder.getUnusedRules(), [

@@ -111,22 +110,22 @@ 'baz-rule',

'plugin/foo-rule',
'scoped-plugin/bar-rule',
])
})
'scoped-plugin/bar-rule'
]);
});
it('specifiedFile (relative path) - current rules', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative)
assert.deepEqual(ruleFinder.getCurrentRules(), ['bar-rule', 'foo-rule', 'scoped-plugin/foo-rule'])
})
it('specifiedFile (relative path) - current rules', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative);
assert.deepEqual(ruleFinder.getCurrentRules(), ['bar-rule', 'foo-rule', 'scoped-plugin/foo-rule']);
});
it('specifiedFile (relative path) - current rule config', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative)
it('specifiedFile (relative path) - current rule config', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative);
assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), {
'bar-rule': [2],
'foo-rule': [2],
'scoped-plugin/foo-rule': [2],
})
})
'scoped-plugin/foo-rule': [2]
});
});
it('specifiedFile (relative path) - plugin rules', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative)
it('specifiedFile (relative path) - plugin rules', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative);
assert.deepEqual(ruleFinder.getPluginRules(), [

@@ -137,8 +136,8 @@ 'plugin/bar-rule',

'scoped-plugin/bar-rule',
'scoped-plugin/foo-rule',
])
})
'scoped-plugin/foo-rule'
]);
});
it('specifiedFile (relative path) - all available rules', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative)
it('specifiedFile (relative path) - all available rules', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative);
assert.deepEqual(

@@ -154,9 +153,9 @@ ruleFinder.getAllAvailableRules(),

'scoped-plugin/bar-rule',
'scoped-plugin/foo-rule',
'scoped-plugin/foo-rule'
]
)
})
);
});
it('specifiedFile (relative path) - all available rules without core', function() {
var ruleFinder = getRuleFinder(specifiedFileRelative, true)
it('specifiedFile (relative path) - all available rules without core', () => {
const ruleFinder = getRuleFinder(specifiedFileRelative, true);
assert.deepEqual(

@@ -169,9 +168,9 @@ ruleFinder.getAllAvailableRules(),

'scoped-plugin/bar-rule',
'scoped-plugin/foo-rule',
'scoped-plugin/foo-rule'
]
)
})
);
});
it('specifiedFile (absolute path) is passed to the constructor', function() {
var ruleFinder = getRuleFinder(specifiedFileAbsolute)
it('specifiedFile (absolute path) is passed to the constructor', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(ruleFinder.getUnusedRules(), [

@@ -182,22 +181,22 @@ 'baz-rule',

'plugin/foo-rule',
'scoped-plugin/bar-rule',
])
})
'scoped-plugin/bar-rule'
]);
});
it('specifiedFile (absolute path) - current rules', function() {
var ruleFinder = getRuleFinder(specifiedFileAbsolute)
assert.deepEqual(ruleFinder.getCurrentRules(), ['bar-rule', 'foo-rule', 'scoped-plugin/foo-rule'])
})
it('specifiedFile (absolute path) - current rules', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(ruleFinder.getCurrentRules(), ['bar-rule', 'foo-rule', 'scoped-plugin/foo-rule']);
});
it('specifiedFile (absolute path) - current rule config', function() {
var ruleFinder = getRuleFinder(specifiedFileAbsolute)
it('specifiedFile (absolute path) - current rule config', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(ruleFinder.getCurrentRulesDetailed(), {
'foo-rule': [2],
'bar-rule': [2],
'scoped-plugin/foo-rule': [2],
})
})
'scoped-plugin/foo-rule': [2]
});
});
it('specifiedFile (absolute path) - plugin rules', function() {
var ruleFinder = getRuleFinder(specifiedFileAbsolute)
it('specifiedFile (absolute path) - plugin rules', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(ruleFinder.getPluginRules(), [

@@ -208,8 +207,8 @@ 'plugin/bar-rule',

'scoped-plugin/bar-rule',
'scoped-plugin/foo-rule',
])
})
'scoped-plugin/foo-rule'
]);
});
it('specifiedFile (absolute path) - all available rules', function() {
var ruleFinder = getRuleFinder(specifiedFileAbsolute)
it('specifiedFile (absolute path) - all available rules', () => {
const ruleFinder = getRuleFinder(specifiedFileAbsolute);
assert.deepEqual(

@@ -225,15 +224,15 @@ ruleFinder.getAllAvailableRules(),

'scoped-plugin/bar-rule',
'scoped-plugin/foo-rule',
'scoped-plugin/foo-rule'
]
)
})
);
});
it('specifiedFile (absolute path) without rules - plugin rules', function() {
var ruleFinder = getRuleFinder(noRulesFile)
it('specifiedFile (absolute path) without rules - plugin rules', () => {
const ruleFinder = getRuleFinder(noRulesFile);
assert.deepEqual(ruleFinder.getPluginRules(), [
'plugin/bar-rule',
'plugin/baz-rule',
'plugin/foo-rule',
])
})
})
'plugin/foo-rule'
]);
});
});

@@ -1,30 +0,30 @@

var assert = require('assert')
var sortRules = require('../../src/lib/sort-rules')
const assert = require('assert');
const sortRules = require('../../src/lib/sort-rules');
describe('sort-rules', function() {
it('should return sorted rules', function() {
describe('sort-rules', () => {
it('should return sorted rules', () => {
assert.deepEqual(
sortRules(['a', 'b', 'c']),
['a', 'b', 'c']
)
);
assert.deepEqual(
sortRules(['c', 'b', 'a']),
['a', 'b', 'c']
)
);
assert.deepEqual(
sortRules(['aa', 'a', 'ab', 'b', 'c']),
['a', 'aa', 'ab', 'b', 'c']
)
})
);
});
it('should return sorted rule configs', function() {
it('should return sorted rule configs', () => {
assert.deepEqual(
sortRules({'bar-rule': {config1: '1', config2: '2'}, 'baz-rule': {config1: '3', config2: '4'}}),
[{'bar-rule': {config1: '1', config2: '2'}}, {'baz-rule': {config1: '3', config2: '4'}}]
)
);
assert.deepEqual(
sortRules({'foo-rule': {config1: '1', config2: '2'}, 'bar-rule': {config1: '3', config2: '4'}}),
[{'bar-rule': {config1: '3', config2: '4'}}, {'foo-rule': {config1: '1', config2: '2'}}]
)
})
})
);
});
});

@@ -1,25 +0,25 @@

var assert = require('assert')
var stringifyRuleConfig = require('../../src/lib/stringify-rule-config')
const assert = require('assert');
const stringifyRuleConfig = require('../../src/lib/stringify-rule-config');
describe('stringify rule config', function() {
it('should return a string', function() {
describe('stringify rule config', () => {
it('should return a string', () => {
assert.equal(
stringifyRuleConfig('A simple string'),
'A simple string'
)
})
);
});
it('should return \'-\' for "undefined"', function() {
it('should return \'-\' for "undefined"', () => {
assert.equal(
stringifyRuleConfig(undefined),
'-'
)
})
);
});
it('should return a JSON.stringify\'ed result for any object', function() {
it('should return a JSON.stringify\'ed result for any object', () => {
assert.deepEqual(
stringifyRuleConfig([2, 'foo', {bar: true}]),
JSON.stringify([2, 'foo', {bar: true}])
)
})
})
);
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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