Socket
Socket
Sign inDemoInstall

lint-staged

Package Overview
Dependencies
Maintainers
1
Versions
250
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 13.0.3 to 13.2.2

6

bin/lint-staged.js

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

import { isColorSupported } from 'colorette'
import { supportsColor } from 'chalk'
import { Option, program } from 'commander'

@@ -16,4 +16,4 @@ import debug from 'debug'

// Force colors for packages that depend on https://www.npmjs.com/package/supports-color
if (isColorSupported) {
process.env.FORCE_COLOR = '1'
if (supportsColor) {
process.env.FORCE_COLOR = supportsColor.level.toString()
}

@@ -20,0 +20,0 @@

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

import { blue, redBright, yellow } from 'colorette'
import chalk from 'chalk'
import { figures } from 'listr2'
export const info = blue(figures.arrowRight)
export const info = chalk.blue(figures.arrowRight)
export const error = redBright(figures.cross)
export const error = chalk.redBright(figures.cross)
export const warning = yellow(figures.warning)
export const warning = chalk.yellow(figures.warning)

@@ -107,12 +107,3 @@ import path from 'node:path'

/**
* https://github.com/okonet/lint-staged/issues/1121
* Detect MSYS in login shell mode and escape braces
* to prevent interpolation
*/
if (!!process.env.MSYSTEM && !!process.env.LOGINSHELL) {
return `refs/stash@\\{${index}\\}`
}
return `refs/stash@{${index}}`
return String(index)
}

@@ -119,0 +110,0 @@

@@ -78,3 +78,4 @@ import debug from 'debug'

shell = false,
stash = true,
// Stashing should be disabled by default when the `diff` option is used
stash = diff === undefined,
verbose = false,

@@ -81,0 +82,0 @@ } = {},

@@ -12,2 +12,4 @@ /** @typedef {import('./index').Logger} Logger */

const PACKAGE_JSON = 'package.json'
/**

@@ -18,3 +20,3 @@ * The list of files `lint-staged` will read configuration

export const searchPlaces = [
'package.json',
PACKAGE_JSON,
'.lintstagedrc',

@@ -32,4 +34,15 @@ '.lintstagedrc.json',

const jsonParse = (path, content) => JSON.parse(content)
const jsonParse = (path, content) => {
try {
return JSON.parse(content)
} catch (error) {
if (path.endsWith(PACKAGE_JSON)) {
debugLog('Ignoring invalid package file `%s` with content:\n%s', path, content)
return undefined
}
throw error
}
}
const yamlParse = (path, content) => YAML.parse(content)

@@ -36,0 +49,0 @@

@@ -1,2 +0,2 @@

import { redBright, bold, yellow } from 'colorette'
import chalk from 'chalk'
import inspect from 'object-inspect'

@@ -7,5 +7,5 @@

export const configurationError = (opt, helpMsg, value) =>
`${redBright(`${error} Validation Error:`)}
`${chalk.redBright(`${error} Validation Error:`)}
Invalid value for '${bold(opt)}': ${bold(
Invalid value for '${chalk.bold(opt)}': ${chalk.bold(
inspect(value, { inlineCharacterLimit: Number.POSITIVE_INFINITY })

@@ -16,8 +16,8 @@ )}

export const NOT_GIT_REPO = redBright(`${error} Current directory is not a git directory!`)
export const NOT_GIT_REPO = chalk.redBright(`${error} Current directory is not a git directory!`)
export const FAILED_GET_STAGED_FILES = redBright(`${error} Failed to get staged files!`)
export const FAILED_GET_STAGED_FILES = chalk.redBright(`${error} Failed to get staged files!`)
export const incorrectBraces = (before, after) =>
yellow(
chalk.yellow(
`${warning} Detected incorrect braces with only single value: \`${before}\`. Reformatted as: \`${after}\`

@@ -41,6 +41,6 @@ `

return yellow(`${warning} Skipping backup because ${reason}.\n`)
return chalk.yellow(`${warning} Skipping backup because ${reason}.\n`)
}
export const DEPRECATED_GIT_ADD = yellow(
export const DEPRECATED_GIT_ADD = chalk.yellow(
`${warning} Some of your tasks use \`git add\` command. Please remove it from the config since all modifications made by tasks will be automatically added to the git commit index.

@@ -54,7 +54,9 @@ `

export const GIT_ERROR = `\n ${redBright(`${error} lint-staged failed due to a git error.`)}`
export const GIT_ERROR = `\n ${chalk.redBright(`${error} lint-staged failed due to a git error.`)}`
export const invalidOption = (name, value, message) => `${redBright(`${error} Validation Error:`)}
export const invalidOption = (name, value, message) => `${chalk.redBright(
`${error} Validation Error:`
)}
Invalid value for option '${bold(name)}': ${bold(value)}
Invalid value for option '${chalk.bold(name)}': ${chalk.bold(value)}

@@ -66,3 +68,3 @@ ${message}

export const PREVENTED_EMPTY_COMMIT = `
${yellow(`${warning} lint-staged prevented an empty git commit.
${chalk.yellow(`${warning} lint-staged prevented an empty git commit.
Use the --allow-empty option to continue, or check your task configuration`)}

@@ -69,0 +71,0 @@ `

@@ -1,2 +0,2 @@

import { redBright, dim } from 'colorette'
import chalk from 'chalk'
import { execa, execaCommand } from 'execa'

@@ -35,3 +35,3 @@ import debug from 'debug'

if (hasOutput) {
const outputTitle = isError ? redBright(`${error} ${command}:`) : `${info} ${command}:`
const outputTitle = isError ? chalk.redBright(`${error} ${command}:`) : `${info} ${command}:`
const output = []

@@ -45,3 +45,3 @@ .concat(ctx.quiet ? [] : ['', outputTitle])

const tag = getTag(result)
const message = redBright(`\n${error} ${command} failed without output (${tag}).`)
const message = chalk.redBright(`\n${error} ${command} failed without output (${tag}).`)
if (!ctx.quiet) ctx.output.push(message)

@@ -121,3 +121,3 @@ }

const tag = getTag(result)
return new Error(`${redBright(command)} ${dim(`[${tag}]`)}`)
return new Error(`${chalk.redBright(command)} ${chalk.dim(`[${tag}]`)}`)
}

@@ -124,0 +124,0 @@

@@ -5,3 +5,3 @@ /** @typedef {import('./index').Logger} Logger */

import { dim } from 'colorette'
import chalk from 'chalk'
import debug from 'debug'

@@ -81,3 +81,4 @@ import { Listr } from 'listr2'

shell = false,
stash = true,
// Stashing should be disabled by default when the `diff` option is used
stash = diff === undefined,
verbose = false,

@@ -109,5 +110,5 @@ },

// Lint-staged should create a backup stash only when there's an initial commit,
// and when using the default list of staged files
ctx.shouldBackup = hasInitialCommit && stash && diff === undefined
// Lint-staged will create a backup stash only when there's an initial commit,
// and when using the default list of staged files by default
ctx.shouldBackup = hasInitialCommit && stash
if (!ctx.shouldBackup) {

@@ -209,3 +210,3 @@ logger.warn(skippingBackup(hasInitialCommit, diff))

return {
title: `${task.pattern}${dim(
title: `${task.pattern}${chalk.dim(
` — ${fileCount} ${fileCount === 1 ? 'file' : 'files'}`

@@ -222,3 +223,3 @@ )}`,

if (fileCount === 0) {
return `${task.pattern}${dim(' — no files')}`
return `${task.pattern}${chalk.dim(' — no files')}`
}

@@ -234,4 +235,4 @@ return false

title:
`${configName}${dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
`${configName}${chalk.dim(` — ${files.length} ${files.length > 1 ? 'files' : 'file'}`)}` +
(chunkCount > 1 ? chalk.dim(` (chunk ${index + 1}/${chunkCount})...`) : ''),
task: (ctx, task) => task.newListr(chunkListrTasks, { concurrent, exitOnError: true }),

@@ -243,3 +244,3 @@ skip: () => {

if (chunkListrTasks.every((task) => task.skip())) {
return `${configName}${dim(' — no tasks to run')}`
return `${configName}${chalk.dim(' — no tasks to run')}`
}

@@ -246,0 +247,0 @@ return false

{
"name": "lint-staged",
"version": "13.0.3",
"version": "13.2.2",
"description": "Lint files staged by git",

@@ -23,2 +23,3 @@ "license": "MIT",

".": "./lib/index.js",
"./bin": "./bin/lint-staged.js",
"./package.json": "./package.json"

@@ -36,33 +37,33 @@ },

"dependencies": {
"chalk": "5.2.0",
"cli-truncate": "^3.1.0",
"colorette": "^2.0.17",
"commander": "^9.3.0",
"commander": "^10.0.0",
"debug": "^4.3.4",
"execa": "^6.1.0",
"lilconfig": "2.0.5",
"listr2": "^4.0.5",
"execa": "^7.0.0",
"lilconfig": "2.1.0",
"listr2": "^5.0.7",
"micromatch": "^4.0.5",
"normalize-path": "^3.0.0",
"object-inspect": "^1.12.2",
"object-inspect": "^1.12.3",
"pidtree": "^0.6.0",
"string-argv": "^0.3.1",
"yaml": "^2.1.1"
"yaml": "^2.2.2"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@babel/preset-env": "^7.18.2",
"babel-jest": "^28.1.1",
"@babel/core": "^7.21.0",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.20.2",
"babel-jest": "^29.5.0",
"babel-plugin-transform-imports": "2.0.0",
"consolemock": "^1.1.0",
"eslint": "^8.17.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint": "^8.35.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.0.0",
"fs-extra": "^10.1.0",
"husky": "^8.0.1",
"jest": "^28.1.1",
"eslint-plugin-prettier": "^4.2.1",
"fs-extra": "^11.1.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-snapshot-serializer-ansi": "^1.0.0",
"prettier": "^2.6.2"
"prettier": "^2.8.4"
},

@@ -69,0 +70,0 @@ "keywords": [

@@ -45,3 +45,3 @@ # 🚫💩 lint-staged ![GitHub Actions](https://github.com/okonet/lint-staged/workflows/CI/badge.svg) [![npm version](https://badge.fury.io/js/lint-staged.svg)](https://badge.fury.io/js/lint-staged) [![Codecov](https://codecov.io/gh/okonet/lint-staged/branch/master/graph/badge.svg)](https://codecov.io/gh/okonet/lint-staged)

- [SurviveJS interview - Juho Vepsäläinen and Andrey Okonetchnikov, 2018](https://survivejs.com/blog/lint-staged-interview/)
- [Prettier your CSharp with `dotnet-format` and `lint-staged`](https://blog.johnnyreilly.com/2020/12/prettier-your-csharp-with-dotnet-format-and-lint-staged.html)
- [Prettier your CSharp with `dotnet-format` and `lint-staged`](https://johnnyreilly.com/2020/12/22/prettier-your-csharp-with-dotnet-format-and-lint-staged)

@@ -130,7 +130,8 @@ > If you've written one, please submit a PR with the link to it!

- uses [debug](https://github.com/visionmedia/debug) internally to log additional information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`.
- uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions).
- uses [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) for `listr2`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
(the [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) can also be activated by setting the `TERM=dumb` or `NODE_ENV=test` environment variables)
- **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). This option also implies `--no-stash`.
- **`--diff-filter`**: By default only files that are _added_, _copied_, _modified_, or _renamed_ are included. Use this flag to override the default `ACMR` value with something else: _added_ (`A`), _copied_ (`C`), _deleted_ (`D`), _modified_ (`M`), _renamed_ (`R`), _type changed_ (`T`), _unmerged_ (`U`), _unknown_ (`X`), or _pairing broken_ (`B`). See also the `git diff` docs for [--diff-filter](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203).
- **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string.
- **`--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-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. Can be re-enabled with `--stash`
- **`--quiet`**: Supress all CLI output, except from tasks.

@@ -226,3 +227,3 @@ - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.

- **`"./*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
- **`"foo/**/\*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js`
- **`"foo/**/*.js"`** will match all JS files inside the `/foo` directory, so `/foo/bar/test.js` but not `/test.js`

@@ -280,3 +281,3 @@ When matching, lint-staged will do the following

Writing the configuration file in JavaScript is the most powerful way to configure lint-staged (`lint-staged.config.js`, [similar](https://github.com/okonet/lint-staged/README.md#configuration), or passed via `--config`). From the configuration file, you can export either a single function or an object.
Writing the configuration file in JavaScript is the most powerful way to configure lint-staged (`lint-staged.config.js`, [similar](https://github.com/okonet/lint-staged#configuration), or passed via `--config`). From the configuration file, you can export either a single function or an object.

@@ -365,3 +366,3 @@ If the `exports` value is a function, it will receive an array of all staged filenames. You can then build your own matchers for the files and return a command string or an array of command strings. These strings are considered complete and should include the filename arguments, if wanted.

It's better to use the [function-based configuration (seen above)](https://github.com/okonet/lint-staged/README.md#example-export-a-function-to-build-your-own-matchers), if your use case is this.
It's better to use the [function-based configuration (seen above)](https://github.com/okonet/lint-staged#example-export-a-function-to-build-your-own-matchers), if your use case is this.

@@ -619,4 +620,45 @@ ```js

### Integrate with Next.js
<details>
<summary>Click to expand</summary>
```js
// .lintstagedrc.js
// See https://nextjs.org/docs/basic-features/eslint#lint-staged for details
const path = require('path')
const buildEslintCommand = (filenames) =>
`next lint --fix --file ${filenames
.map((f) => path.relative(process.cwd(), f))
.join(' --file ')}`
module.exports = {
'*.{js,jsx,ts,tsx}': [buildEslintCommand],
}
```
</details>
## Frequently Asked Questions
### The output of commit hook looks weird (no colors, duplicate lines, …)
<details>
<summary>Click to expand</summary>
Git 2.36.0 introduced a change to hooks where they were no longer run in the original TTY.
This was fixed in 2.37.0:
https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.37.0.txt
> - In Git 2.36 we revamped the way how hooks are invoked. One change
> that is end-user visible is that the output of a hook is no longer
> directly connected to the standard output of "git" that spawns the
> hook, which was noticed post release. This is getting corrected.
> (merge [a082345372](https://github.com/git/git/commit/a082345372) ab/hooks-regression-fix later to maint).
</details>
### Can I use `lint-staged` via node?

@@ -752,2 +794,4 @@

To support backwards-compatibility, monorepo features require multiple _lint-staged_ configuration files present in the git repo. If you still want to run _lint-staged_ in only one of the packages in a monorepo, you can either add an "empty" _lint-staged_ configuration to the root of the repo (so that there's two configs in total), or alternatively run _lint-staged_ with the `--cwd` option pointing to your package directory (for example, `lint-staged --cwd packages/frontend`).
</details>

@@ -754,0 +798,0 @@

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