Skip to content

Commit

Permalink
refactor: Drop support for Node.js 4 (#399)
Browse files Browse the repository at this point in the history
- Change Node.js requirement in `engines.node` to `>=6`. Use
  `please-upgrade-node` to give helpful error message on older versions.
- Remove node 4 from list of Node.js versions to test on CI. Also remove
  `--ignore-engines` flag for `yarn install`, not required with node 6.
- Add note to readme for Node.js version requirement.
- Target node 6 for `babel-preset-env` (relevant only for tests).
- Add eslint rule for `prefer-destructuring`, do relevant code changes.
- Use default argument for `logger` passed to `src/index.js`

BREAKING CHANGE: Requires Node.js v6 or later.
  • Loading branch information
sudo-suhas committed Feb 21, 2018
1 parent d8b836c commit 05a062d
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["env", {
"targets": {
"node": 4
"node": 6
}
}]
]
Expand Down
15 changes: 14 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
"error",
"global"
],
"no-console": "off"
"no-console": "off",
"prefer-destructuring": [
"error",
{
"VariableDeclarator": {
"array": true,
"object": true
},
"AssignmentExpression": {
"array": false,
"object": false
}
}
]
}
}
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ cache:
node_js:
- '8'
- '6'
- '4'

before_install: yarn global add greenkeeper-lockfile@1
install: yarn install --ignore-engines
install: yarn install

before_script: greenkeeper-lockfile-update
after_script: greenkeeper-lockfile-upload
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Run linters against staged git files and don't let :poop: slip into your code base!

The latest versions of `lint-staged` require Node.js v6 or newer. (Versions of `lint-staged` prior to v7 still work with Node.js v4.)

## Why

Linting makes more sense when running before committing your code. By doing that you can ensure no errors are going into repository and enforce code style. But running a lint process on a whole project is slow and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
Expand Down
3 changes: 1 addition & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ environment:
matrix:
- nodejs_version: '8'
- nodejs_version: '6'
- nodejs_version: '4'

install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
- yarn install --ignore-engines
- yarn install

test_script:
- node --version
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

'use strict'

const pkg = require('./package.json')
require('please-upgrade-node')(pkg)

const cmdline = require('commander')
const debugLib = require('debug')
const pkg = require('./package.json')

const debug = debugLib('lint-staged:bin')

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Suhas Karanth <[email protected]>"
],
"engines": {
"node": ">=4.2.0"
"node": ">=6"
},
"bin": "index.js",
"files": [
Expand Down Expand Up @@ -45,6 +45,7 @@
"p-map": "^1.1.1",
"path-is-inside": "^1.0.2",
"pify": "^3.0.0",
"please-upgrade-node": "^3.0.1",
"staged-git-files": "1.0.0",
"stringify-object": "^3.2.0"
},
Expand Down
9 changes: 5 additions & 4 deletions src/checkPkgScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const warn = msg => {
*/
module.exports = function checkPkgScripts(pkg, cmd, binName, args) {
if (pkg && pkg.scripts) {
const { scripts } = pkg
let scriptName
let script
if (has(pkg.scripts, cmd)) {
if (has(scripts, cmd)) {
scriptName = cmd
script = pkg.scripts[cmd]
} else if (has(pkg.scripts, binName)) {
script = scripts[cmd]
} else if (has(scripts, binName)) {
scriptName = binName
script = pkg.scripts[binName]
script = scripts[binName]
} else {
return
}
Expand Down
4 changes: 1 addition & 3 deletions src/findBin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ module.exports = function findBin(cmd) {
* "*.js": "eslint"
* }
*/
const parts = cmd.split(' ')
const binName = parts[0]
const args = parts.splice(1)
const [binName, ...args] = cmd.split(' ')

if (cache.has(binName)) {
debug('Resolving binary for `%s` from cache', binName)
Expand Down
5 changes: 2 additions & 3 deletions src/generateTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const path = require('path')
const micromatch = require('micromatch')
const pathIsInside = require('path-is-inside')
const getConfig = require('./getConfig').getConfig
const { getConfig } = require('./getConfig')
const resolveGitDir = require('./resolveGitDir')

const debug = require('debug')('lint-staged:gen-tasks')
Expand All @@ -12,8 +12,7 @@ module.exports = function generateTasks(config, relFiles) {
debug('Generating linter tasks')

const normalizedConfig = getConfig(config) // Ensure we have a normalized config
const linters = normalizedConfig.linters
const globOptions = normalizedConfig.globOptions
const { linters, globOptions } = normalizedConfig
const ignorePatterns = normalizedConfig.ignore.map(pattern => `!${pattern}`)

const gitDir = resolveGitDir()
Expand Down
7 changes: 3 additions & 4 deletions src/getConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ const format = require('stringify-object')
const intersection = require('lodash/intersection')
const defaultsDeep = require('lodash/defaultsDeep')
const isObject = require('lodash/isObject')
const validate = require('jest-validate').validate
const logValidationWarning = require('jest-validate').logValidationWarning
const unknownOptionWarning = require('jest-validate/build/warnings').unknownOptionWarning
const { validate, logValidationWarning } = require('jest-validate')
const { unknownOptionWarning } = require('jest-validate/build/warnings')
const isGlob = require('is-glob')

const debug = require('debug')('lint-staged:cfg')
Expand Down Expand Up @@ -73,7 +72,7 @@ function unknownValidationReporter(config, example, option, options) {
will fix it and remove this message.`

const comment = options.comment
const { comment } = options
const name = options.title.warning
return logValidationWarning(name, message, comment)
}
Expand Down
6 changes: 2 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
const dedent = require('dedent')
const cosmiconfig = require('cosmiconfig')
const stringifyObject = require('stringify-object')
const getConfig = require('./getConfig').getConfig
const validateConfig = require('./getConfig').validateConfig
const { getConfig, validateConfig } = require('./getConfig')
const printErrors = require('./printErrors')
const runAll = require('./runAll')

Expand All @@ -23,9 +22,8 @@ const errConfigNotFound = new Error('Config could not be found')
/**
* Root lint-staged function that is called from .bin
*/
module.exports = function lintStaged(injectedLogger, configPath, debugMode) {
module.exports = function lintStaged(logger = console, configPath, debugMode) {
debug('Loading config using `cosmiconfig`')
const logger = injectedLogger || console

const explorer = cosmiconfig('lint-staged', {
configPath,
Expand Down
3 changes: 1 addition & 2 deletions src/runAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ module.exports = function runAll(config) {
throw new Error('Invalid config provided to runAll! Use getConfig instead.')
}

const concurrent = config.concurrent
const renderer = config.renderer
const { concurrent, renderer } = config
const gitDir = resolveGitDir()
debug('Resolved git directory to be `%s`', gitDir)

Expand Down
5 changes: 2 additions & 3 deletions src/runScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const dedent = require('dedent')
const execa = require('execa')
const logSymbols = require('log-symbols')
const pMap = require('p-map')
const getConfig = require('./getConfig').getConfig
const { getConfig } = require('./getConfig')
const calcChunkSize = require('./calcChunkSize')
const findBin = require('./findBin')
const resolveGitDir = require('./resolveGitDir')
Expand All @@ -16,8 +16,7 @@ module.exports = function runScript(commands, pathsToLint, config) {
debug('Running script with commands %o', commands)

const normalizedConfig = getConfig(config)
const chunkSize = normalizedConfig.chunkSize
const concurrency = normalizedConfig.subTaskConcurrency
const { chunkSize, subTaskConcurrency: concurrency } = normalizedConfig
const gitDir = resolveGitDir()

const filePathChunks = chunk(pathsToLint, calcChunkSize(pathsToLint, chunkSize))
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3699,6 +3699,10 @@ pkg-dir@^1.0.0:
dependencies:
find-up "^1.0.0"

please-upgrade-node@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/please-upgrade-node/-/please-upgrade-node-3.0.1.tgz#0a681f2c18915e5433a5ca2cd94e0b8206a782db"

pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"
Expand Down

0 comments on commit 05a062d

Please sign in to comment.