New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lint-staged

Package Overview
Dependencies
Maintainers
1
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lint-staged - npm Package Compare versions

Comparing version 3.3.1 to 3.3.2

test/__mocks__/execa.js

11

package.json

@@ -13,3 +13,3 @@ {

"pre-commit": "node index.js",
"test": "mocha --compilers js:babel-register ./test/*.spec.js",
"test": "jest --coverage",
"deps": "npm-check -s",

@@ -55,7 +55,7 @@ "deps:update": "npm-check -u",

"npm-which": "^3.0.1",
"staged-git-files": "0.0.4",
"which": "^1.2.11"
"staged-git-files": "0.0.4"
},
"devDependencies": {
"babel-core": "^6.10.4",
"babel-jest": "^19.0.0",
"babel-preset-es2015": "^6.9.0",

@@ -69,8 +69,7 @@ "babel-preset-stage-0": "^6.5.0",

"is-promise": "^2.1.0",
"jest": "^19.0.2",
"jsonlint": "^1.6.2",
"jsonlint-cli": "^1.0.1",
"mocha": "^3.1.0",
"npm-check": "^5.2.2",
"pre-commit": "^1.1.3",
"rewire": "^2.5.1",
"semantic-release": "^6.3.2"

@@ -83,3 +82,3 @@ },

},
"version": "3.3.1"
"version": "3.3.2"
}

@@ -13,2 +13,8 @@ # lint-staged [![Build Status](https://travis-ci.org/okonet/lint-staged.svg?branch=master)](https://travis-ci.org/okonet/lint-staged) [![npm version](https://badge.fury.io/js/lint-staged.svg)](https://badge.fury.io/js/lint-staged)

## Related blogs posts
* [Running Jest Tests Before Each Git Commit](https://benmccormick.org/2017/02/26/running-jest-tests-before-each-git-commit/)
> If you've written one, please submit a PR with the link to it!
## Installation & Setup

@@ -126,3 +132,3 @@

Starting from v3.1, lint-staged will stash you remaining changes (not added to the index) and restore them from stash afterwards. This allows you to create partial commits with hunks using `git add --patch`.
~~Starting from v3.1, lint-staged will stash you remaining changes (not added to the index) and restore them from stash afterwards. This allows you to create partial commits with hunks using `git add --patch`.~~ This is still [not resolved](https://github.com/okonet/lint-staged/issues/62)

@@ -129,0 +135,0 @@ ## Working from a sub-directory

'use strict'
const npmWhich = require('npm-which')(process.cwd())
const which = require('which')

@@ -49,11 +48,7 @@ module.exports = function findBin(cmd, paths, packageJson, options) {

try {
/* Firstly, try to resolve the bin in local node_modules/.bin */
/* npm-which tries to resolve the bin in local node_modules/.bin */
/* and if this fails it look in $PATH */
bin = npmWhich.sync(bin)
} catch (err) {
/* If this fails, try to resolve binary in $PATH */
try {
bin = which.sync(bin)
} catch (error) {
throw new Error(`${ bin } could not be found. Try \`npm install ${ bin }\`.`)
}
throw new Error(`${ bin } could not be found. Try \`npm install ${ bin }\`.`)
}

@@ -60,0 +55,0 @@

@@ -18,11 +18,8 @@ 'use strict'

.then(() => {
resolve(`${ linter } passed!`)
resolve(`✅ ${ linter } passed!`)
})
.catch((err) => {
reject(new Error(`
🚫 ${ linter } found some errors. Please fix them and try committing again.
reject(new Error(`🚫 ${ linter } found some errors. Please fix them and try committing again.
${ err.stderr }
${ err.stdout }
`))
${ err.stdout }`))
})

@@ -29,0 +26,0 @@ })

@@ -1,7 +0,6 @@

/* eslint no-underscore-dangle: 0 */
import expect from 'expect'
import rewire from 'rewire'
import findBin from '../src/findBin'
const findBin = rewire('../src/findBin')
jest.mock('npm-which')
const packageJSON = {

@@ -13,23 +12,14 @@ scripts: {

}
const npmWichMockGood = {
sync: path => path
}
const npmWichMockBad = {
sync: (path) => {
throw new Error(`not found: ${ path }`)
}
}
describe('findBin', () => {
it('should return npm run command if it exist in both package.json and .bin/', () => {
it('should favor `npm run` command if exists in both package.json and .bin/', () => {
const packageJSONMock = {
scripts: {
eslint: 'eslint'
'my-linter': 'my-linter'
}
}
findBin.__set__('npmWhich', npmWichMockGood)
const { bin, args } = findBin('eslint', 'test.js', packageJSONMock)
const { bin, args } = findBin('my-linter', 'test.js', packageJSONMock)
expect(bin).toEqual('npm')
expect(args).toEqual(['run', '--silent', 'eslint', '--', 'test.js'])
expect(args).toEqual(['run', '--silent', 'my-linter', '--', 'test.js'])
})

@@ -43,4 +33,2 @@

}
findBin.__set__('npmWhich', npmWichMockGood)
const { bin, args } = findBin('eslint', 'test.js', packageJSONMock, { verbose: true })

@@ -51,31 +39,20 @@ expect(bin).toEqual('npm')

it('should return bin from node_modules/.bin if there is no command in package.json', () => {
findBin.__set__('npmWhich', npmWichMockGood)
const { bin, args } = findBin('eslint', 'test.js test2.js', packageJSON)
expect(bin).toEqual('eslint')
it('should return path to bin if there is no `script` with name in package.json', () => {
const { bin, args } = findBin('my-linter', 'test.js test2.js', packageJSON)
expect(bin).toEqual('my-linter')
expect(args).toEqual(['--', 'test.js test2.js'])
})
it('should parse cmd and add arguments to args', () => {
findBin.__set__('npmWhich', npmWichMockGood)
const { bin, args } = findBin('eslint --fix', 'test.js test2.js', packageJSON)
expect(bin).toEqual('eslint')
expect(args).toEqual(['--fix', '--', 'test.js test2.js'])
it('should throw an error if bin not found and there is no entry in scripts section', () => {
expect(() => {
findBin('my-missing-linter', 'test.js', packageJSON)
}).toThrow('my-missing-linter could not be found. Try `npm install my-missing-linter`.')
})
it('should return bin from $PATH if there is no command in package.json and no bin in node_modules', () => {
findBin.__set__('npmWhich', npmWichMockBad)
findBin.__set__('which', npmWichMockGood)
const { bin, args } = findBin('git add', 'test.js test2.js', packageJSON)
expect(bin).toEqual('git')
expect(args).toEqual(['add', '--', 'test.js test2.js'])
})
it('should throw error if bin not found and there is no entry in scripts section', () => {
findBin.__set__('npmWhich', npmWichMockBad)
findBin.__set__('which', npmWichMockBad)
expect(() => {
findBin('eslint', 'test.js', packageJSON)
}).toThrow('eslint could not be found. Try `npm install eslint`.')
it('should parse cmd and add arguments to args', () => {
const { bin, args } = findBin('my-linter task --fix', 'test.js test2.js', packageJSON)
expect(bin).toEqual('my-linter')
expect(args).toEqual(['task', '--fix', '--', 'test.js test2.js'])
})
})

@@ -5,5 +5,6 @@ /* eslint no-underscore-dangle: 0 */

import isPromise from 'is-promise'
import rewire from 'rewire'
import mockFn from 'execa'
import runScript from '../src/runScript'
const runScript = rewire('../src/runScript')
jest.mock('execa')

@@ -30,4 +31,5 @@ expect.extend({

describe('runScript', () => {
afterEach(() => {
expect.restoreSpies()
beforeEach(() => {
mockFn.mockReset()
})

@@ -40,3 +42,5 @@

it('should throw for non-existend script', () => {
expect(runScript('test3', 'test.js', packageJSON)[0].task).toThrow()
expect(() => {
runScript('missing-module', 'test.js', packageJSON)[0].task()
}).toThrow()
})

@@ -52,5 +56,3 @@

it('should support array of scripts as a first argument', () => {
const spy = expect.createSpy()
runScript.__set__('execa', spy)
it('should work with multiple commands', () => {
const res = runScript(['test', 'test2'], 'test.js', packageJSON)

@@ -62,10 +64,9 @@ expect(res.length).toBe(2)

expect(res[0].task()).toBeAPromise()
expect(spy.calls.length).toEqual(1)
expect(spy.calls[0].arguments).toEqual(
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0]).toEqual(
['npm', ['run', '--silent', 'test', '--', 'test.js'], {}]
)
expect(res[1].task()).toBeAPromise()
expect(spy.calls.length).toEqual(2)
expect(spy.calls[1].arguments).toEqual(
expect(mockFn.mock.calls.length).toEqual(2)
expect(mockFn.mock.calls[1]).toEqual(
['npm', ['run', '--silent', 'test2', '--', 'test.js'], {}]

@@ -76,4 +77,2 @@ )

it('should support non npm scripts', () => {
const spy = expect.createSpy()
runScript.__set__('execa', spy)
const res = runScript(['node --arg=true ./myscript.js', 'git add'], 'test.js', packageJSON)

@@ -85,15 +84,13 @@ expect(res.length).toBe(2)

expect(res[0].task()).toBeAPromise()
expect(spy.calls.length).toEqual(1)
expect(spy.calls[0].arguments[0]).toContain('node')
expect(spy.calls[0].arguments[1]).toEqual(['--arg=true', './myscript.js', '--', 'test.js'])
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0][0]).toContain('node')
expect(mockFn.mock.calls[0][1]).toEqual(['--arg=true', './myscript.js', '--', 'test.js'])
expect(res[1].task()).toBeAPromise()
expect(spy.calls.length).toEqual(2)
expect(spy.calls[1].arguments[0]).toContain('git')
expect(spy.calls[1].arguments[1]).toEqual(['add', '--', 'test.js'])
expect(mockFn.mock.calls.length).toEqual(2)
expect(mockFn.mock.calls[1][0]).toContain('git')
expect(mockFn.mock.calls[1][1]).toEqual(['add', '--', 'test.js'])
})
it('should pass cwd to execa if gitDir option is set for non-npm tasks', () => {
const spy = expect.createSpy()
runScript.__set__('execa', spy)
const res = runScript(

@@ -106,4 +103,4 @@ ['test', 'git add'],

expect(res[0].task()).toBeAPromise()
expect(spy.calls.length).toEqual(1)
expect(spy.calls[0].arguments).toEqual(
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0]).toEqual(
['npm', ['run', '--silent', 'test', '--', 'test.js'], {}]

@@ -113,11 +110,9 @@ )

expect(res[1].task()).toBeAPromise()
expect(spy.calls.length).toEqual(2)
expect(spy.calls[1].arguments[0]).toMatch(/git$/)
expect(spy.calls[1].arguments[1]).toEqual(['add', '--', 'test.js'])
expect(spy.calls[1].arguments[2]).toEqual({ cwd: '../' })
expect(mockFn.mock.calls.length).toEqual(2)
expect(mockFn.mock.calls[1][0]).toMatch(/git$/)
expect(mockFn.mock.calls[1][1]).toEqual(['add', '--', 'test.js'])
expect(mockFn.mock.calls[1][2]).toEqual({ cwd: '../' })
})
it('should use --silent in non-verbose mode', () => {
const spy = expect.createSpy()
runScript.__set__('execa', spy)
const res = runScript(

@@ -130,4 +125,4 @@ 'test',

expect(res[0].task()).toBeAPromise()
expect(spy.calls.length).toEqual(1)
expect(spy.calls[0].arguments).toEqual(
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0]).toEqual(
['npm', ['run', '--silent', 'test', '--', 'test.js'], {}]

@@ -138,4 +133,2 @@ )

it('should not use --silent in verbose mode', () => {
const spy = expect.createSpy()
runScript.__set__('execa', spy)
const res = runScript(

@@ -148,4 +141,4 @@ 'test',

expect(res[0].task()).toBeAPromise()
expect(spy.calls.length).toEqual(1)
expect(spy.calls[0].arguments).toEqual(
expect(mockFn.mock.calls.length).toEqual(1)
expect(mockFn.mock.calls[0]).toEqual(
['npm', ['run', 'test', '--', 'test.js'], {}]

@@ -152,0 +145,0 @@ )

@@ -5,3 +5,5 @@ module.exports = function (wallaby) {

{ pattern: 'test/__fixtures__/*', instrument: false },
'src/*.js'
'src/*.js',
'src/__mocks__/*.js',
'!test/*.spec.js'
],

@@ -14,3 +16,4 @@

env: {
type: 'node'
type: 'node',
runner: 'node'
},

@@ -22,4 +25,4 @@

testFramework: 'mocha'
testFramework: 'jest'
}
}

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