Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: lint-staged/lint-staged
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v11.1.2
Choose a base ref
...
head repository: lint-staged/lint-staged
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9b4fff70cd5c428b12afe04a56f4dc81ea3f94ba
Choose a head ref
  • 12 commits
  • 22 files changed
  • 5 contributors

Commits on Aug 26, 2021

  1. Copy the full SHA
    ad4316c View commit details

Commits on Sep 8, 2021

  1. docs: simplify Ignoring Files From .eslintignore. (#1013)

    The README advised ESLint >= 7 users to install node-filter-async.
    Replace this suggestion with a simpler implementation requiring the same
    number of lines of code but no dependencies. Rename the variable
    eslintCli to eslint since it is an instance of the ESLint Node.js API as
    distinct from the ESLint CLI. Avoid instantiating the API when the files
    staged don't necessitate invocation of ESLint.
    Kurt-von-Laven authored Sep 8, 2021
    Copy the full SHA
    0ef25e8 View commit details

Commits on Sep 27, 2021

  1. docs: Use /usr/bin/env sh instead of direct path (#1020)

    Co-authored-by: nathandao <nd@nathan.fi>
    nathandao and nathandao authored Sep 27, 2021
    Copy the full SHA
    3885af8 View commit details

Commits on Sep 28, 2021

  1. perf: do not use a git stash

    iiroj committed Sep 28, 2021
    Copy the full SHA
    86089c9 View commit details
  2. Copy the full SHA
    8a384aa View commit details
  3. test: update most of the tests

    iiroj committed Sep 28, 2021
    Copy the full SHA
    b526ddb View commit details

Commits on Oct 2, 2021

  1. chore: remove unused code

    iiroj committed Oct 2, 2021
    Copy the full SHA
    8dbfa4b View commit details
  2. Copy the full SHA
    7eb4436 View commit details
  3. Copy the full SHA
    9e8d24f View commit details
  4. Copy the full SHA
    ae2cd99 View commit details
  5. Copy the full SHA
    ae47feb View commit details
  6. Copy the full SHA
    9b4fff7 View commit details
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

node bin/lint-staged.js
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -65,8 +65,7 @@ Options:
(default: false)
-c, --config [path] path to configuration file, or - to read from stdin
-d, --debug print additional debug information (default: false)
--no-stash disable the backup stash, and do not revert in case of
errors
--no-reset do not reset changes in case of errors
-p, --concurrent <parallel tasks> the number of tasks to run concurrently, or false to run
tasks serially (default: true)
-q, --quiet disable lint-staged’s own console output (default: false)
@@ -87,7 +86,7 @@ Options:
- `false`: Run all tasks serially
- `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
- `{number}`: Run the specified number of tasks in parallel, where `1` is equivalent to `false`.
- **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit.
- **`--no-reset`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit.
- **`--quiet`**: Supress all CLI output, except from tasks.
- **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
- **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option. To use a specific shell, use a path like `--shell "/bin/bash"`.
@@ -369,7 +368,7 @@ All examples assume you've already set up lint-staged in the `package.json` file
In `.husky/pre-commit`
```shell
#!/bin/sh
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
npx lint-staged
@@ -565,8 +564,8 @@ const success = await lintStaged({
maxArgLength: null,
quiet: false,
relative: false,
reset: true,
shell: false
stash: true,
verbose: false
})
```
@@ -583,8 +582,8 @@ const success = await lintStaged({
maxArgLength: null,
quiet: false,
relative: false,
reset: true,
shell: false,
stash: true,
verbose: false,
})
```
@@ -671,8 +670,6 @@ Example repo: [sudo-suhas/lint-staged-django-react-demo](https://github.com/sudo
ESLint throws out `warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override` warnings that breaks the linting process ( if you used `--max-warnings=0` which is recommended ).
</details>
#### ESLint < 7
<details>
@@ -702,21 +699,19 @@ module.exports = {
In versions of ESLint > 7, [isPathIgnored](https://eslint.org/docs/developer-guide/nodejs-api#-eslintispathignoredfilepath) is an async function and now returns a promise. The code below can be used to reinstate the above functionality.
This particular code uses a tiny package, [node-filter-async](https://www.npmjs.com/package/node-filter-async), to filter the files array with an async function. If you prefer to not have an extra dependency, it is quite simple to write a similar function.
Since [10.5.3](https://github.com/okonet/lint-staged/releases), any errors due to a bad ESLint config will come through to the console.
```js
const { ESLint } = require('eslint')
const filterAsync = require('node-filter-async').default
const eslintCli = new ESLint()
const removeIgnoredFiles = async (files) => {
const filteredFiles = await filterAsync(files, async (file) => {
const isIgnored = await eslintCli.isPathIgnored(file)
return !isIgnored
})
const eslint = new ESLint()
const isIgnored = await Promise.all(
files.map((file) => {
return eslint.isPathIgnored(file)
})
)
const filteredFiles = files.filter((_, i) => !isIgnored[i])
return filteredFiles.join(' ')
}
@@ -729,3 +724,5 @@ module.exports = {
```
</details>
</details>
40 changes: 24 additions & 16 deletions bin/lint-staged.js
Original file line number Diff line number Diff line change
@@ -22,19 +22,22 @@ require('please-upgrade-node')(
})
)

const cmdline = require('commander')
const { Command, Option } = require('commander')
const debugLib = require('debug')
const lintStaged = require('../lib')
const { CONFIG_STDIN_ERROR } = require('../lib/messages')

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

cmdline
.version(pkg.version)
const program = new Command('lint-staged')

program.version(pkg.version)

program
.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
.option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
.option('-d, --debug', 'print additional debug information', false)
.option('--no-stash', 'disable the backup stash, and do not revert in case of errors', false)
.option('--no-reset', 'do not reset changes in case of errors', false)
.option(
'-p, --concurrent <parallel tasks>',
'the number of tasks to run concurrently, or false to run tasks serially',
@@ -48,9 +51,13 @@ cmdline
'show task output even when tasks succeed; by default only failed output is shown',
false
)
.parse(process.argv)

if (cmdline.debug) {
// Added for backwards-compatibility
program.addOption(new Option('--no-stash').hideHelp())

program.parse(process.argv)

if (program.debug) {
debugLib.enable('lint-staged*')
}

@@ -74,19 +81,20 @@ const getMaxArgLength = () => {
}
}

const cmdlineOptions = cmdline.opts()
const programOpts = program.opts()

const options = {
allowEmpty: !!cmdlineOptions.allowEmpty,
concurrent: JSON.parse(cmdlineOptions.concurrent),
configPath: cmdlineOptions.config,
debug: !!cmdlineOptions.debug,
allowEmpty: !!programOpts.allowEmpty,
concurrent: JSON.parse(programOpts.concurrent),
configPath: programOpts.config,
debug: !!programOpts.debug,
maxArgLength: getMaxArgLength() / 2,
stash: !!cmdlineOptions.stash, // commander inverts `no-<x>` flags to `!x`
quiet: !!cmdlineOptions.quiet,
relative: !!cmdlineOptions.relative,
shell: cmdlineOptions.shell /* Either a boolean or a string pointing to the shell */,
verbose: !!cmdlineOptions.verbose,
quiet: !!programOpts.quiet,
relative: !!programOpts.relative,
reset: !!programOpts.reset, // commander inverts `no-<x>` flags to `!x`
shell: programOpts.shell /* Either a boolean or a string pointing to the shell */,
stash: programOpts.stash /** kept for backwards-compatibility */,
verbose: !!programOpts.verbose,
}

debug('Options parsed from command-line:', options)
63 changes: 0 additions & 63 deletions lib/file.js

This file was deleted.

Loading