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

eslint-find-rules

Package Overview
Dependencies
Maintainers
2
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.4.0 to 1.5.0

src/lib/cli-util.js

4

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

@@ -39,3 +39,3 @@ "main": "src/lib/rule-finder.js",

"codecov": "1.0.1",
"commitizen": "2.7.6",
"commitizen": "2.8.0",
"cz-conventional-changelog": "1.1.5",

@@ -42,0 +42,0 @@ "eslint": "2.8.0",

@@ -5,6 +5,6 @@ #!/usr/bin/env node

var size = require('window-size')
var availableWidth = size.width || /* istanbul ignore next */ 80
var ui = require('cliui')({width: availableWidth})
var path = require('path')
var cli = require('../lib/cli-util')
var getRuleFinder = require('../lib/rule-finder')

@@ -14,35 +14,51 @@ var difference = require('../lib/array-diff')

var rules = getSortedRules(
difference(
getRuleFinder(process.argv[2]).getCurrentRules(),
getRuleFinder(process.argv[3]).getCurrentRules()
)
)
var files = [process.argv[2], process.argv[3]]
var collectedRules = getFilesToCompare(files).map(compareConfigs)
var outputRules, outputRuleCellMapper
var outputPadding = ' '
var outputMaxWidth = 0
var outputMaxCols = 0
var rulesCount = collectedRules.reduce(
function getLength(prev, curr) {
return prev + (curr && curr.rules ? curr.rules.length : /* istanbul ignore next */ 0)
}, 0)
/* istanbul ignore next */
if (rules.length) {
console.log('\n diff rules\n') // eslint-disable-line no-console
rules = rules.map(function columnSpecification(rule) {
rule = rule + outputPadding
outputMaxWidth = Math.max(rule.length, outputMaxWidth)
return rule
if (rulesCount) {
cli.push('\ndiff rules\n')
collectedRules.forEach(function displayConfigs(diff) {
var rules = diff.rules
if (!rules.length) {
return
}
cli.push('\nin ' + diff.config1 + ' but not in ' + diff.config2 + ':\n')
cli.push(rules)
})
outputMaxCols = Math.floor(availableWidth / outputMaxWidth)
outputRuleCellMapper = getOutputRuleCellMapper(Math.floor(availableWidth / outputMaxCols))
while (rules.length) {
outputRules = rules.splice(0, outputMaxCols).map(outputRuleCellMapper)
ui.div.apply(ui, outputRules)
}
console.log(ui.toString()) // eslint-disable-line no-console
}
function getOutputRuleCellMapper(width) {
return function curriedOutputRuleCellMapper(rule) {
return {text: rule, width: width}
cli.write()
function getFilesToCompare(allFiles) {
var filesToCompare = [allFiles]
filesToCompare.push([].concat(allFiles).reverse())
return filesToCompare
}
function compareConfigs(currentFiles) {
return {
config1: path.basename(currentFiles[0]),
config2: path.basename(currentFiles[1]),
rules: rulesDifference(
getRuleFinder(currentFiles[0]),
getRuleFinder(currentFiles[1])
),
}
}
function rulesDifference(a, b) {
return getSortedRules(
difference(
a.getCurrentRules(),
b.getCurrentRules()
)
)
}

@@ -18,5 +18,3 @@ #!/usr/bin/env node

var size = require('window-size')
var availableWidth = size.width || /* istanbul ignore next */ 80
var ui = require('cliui')({width: availableWidth})
var cli = require('../lib/cli-util')

@@ -29,6 +27,3 @@ var processExitCode = argv.u && !argv.n ? 1 : 0

Object.keys(options).forEach(function findRules(option) {
var rules, outputRules, outputRuleCellMapper
var outputPadding = ' '
var outputMaxWidth = 0
var outputMaxCols = 0
var rules
var ruleFinderMethod = ruleFinder[option]

@@ -39,15 +34,5 @@ if (argv[option] && ruleFinderMethod) {

if (rules.length) {
console.log('\n' + options[option][0], 'rules\n') // eslint-disable-line no-console
rules = rules.map(function columnSpecification(rule) {
rule = rule + outputPadding
outputMaxWidth = Math.max(rule.length, outputMaxWidth)
return rule
})
outputMaxCols = Math.floor(availableWidth / outputMaxWidth)
outputRuleCellMapper = getOutputRuleCellMapper(Math.floor(availableWidth / outputMaxCols))
while (rules.length) {
outputRules = rules.splice(0, outputMaxCols).map(outputRuleCellMapper)
ui.div.apply(ui, outputRules)
}
console.log(ui.toString()) // eslint-disable-line no-console
cli.push('\n' + options[option][0] + ' rules\n')
cli.push(rules)
cli.write()
} else if (option === 'getUnusedRules') {

@@ -62,7 +47,1 @@ processExitCode = 0

}
function getOutputRuleCellMapper(width) {
return function curriedOutputRuleCellMapper(rule) {
return {text: rule, width: width}
}
}

@@ -7,4 +7,2 @@ var assert = require('assert')

var difference = sinon.stub().returns(['diff'])
var stub = {

@@ -16,3 +14,3 @@ '../lib/rule-finder': function() {

},
'../lib/array-diff': difference,
'../lib/array-diff': sinon.stub().returns(['diff']),
}

@@ -24,6 +22,12 @@

process.argv = process.argv.slice(0, 2)
sinon.stub(console, 'log', function() {
// print out everything but the test target's output
if (!arguments[0].match(/diff/)) {
consoleLog.apply(null, arguments)
}
})
})
afterEach(function() {
console.log = consoleLog // eslint-disable-line no-console
console.log.restore() // eslint-disable-line no-console
})

@@ -34,11 +38,11 @@

process.argv[3] = './bar'
console.log = function() { // eslint-disable-line no-console
if (arguments[0].match(/(diff)/)) {
return
}
consoleLog.apply(null, arguments)
}
proxyquire('../../src/bin/diff', stub)
assert.ok(difference.called)
assert.ok(
console.log.calledWith( // eslint-disable-line no-console
sinon.match(
/diff rules[^]*in foo but not in bar:[^]*diff[^]*in bar but not in foo:[^]*diff/
)
)
)
})
})
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