]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/contribute/package-json-conventions.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / contribute / package-json-conventions.md
CommitLineData
8f9d1d4d
DC
1---
2title: Package.json Conventions
f2a92ac6 3edit_link: https://github.com/eslint/eslint/edit/main/docs/src/contribute/package-json-conventions.md
8f9d1d4d
DC
4---
5
6The following applies to the "scripts" section of `package.json` files.
7
8## Names
9
10npm script names MUST contain only lower case letters, `:` to separate parts, `-` to separate words, and `+` to separate file extensions. Each part name SHOULD be either a full English word (e.g. `coverage` not `cov`) or a well-known initialism in all lowercase (e.g. `wasm`).
11
f2a92ac6 12Here is a summary of the proposal in ABNF.
8f9d1d4d 13
f2a92ac6
DC
14```abnf
15name = life-cycle / main target? option* ":watch"?
16life-cycle = "prepare" / "preinstall" / "install" / "postinstall" / "prepublish" / "preprepare" / "prepare" / "postprepare" / "prepack" / "postpack" / "prepublishOnly"
17main = "build" / "lint" ":fix"? / "release" / "start" / "test"
18target = ":" word ("-" word)* / extension ("+" extension)*
19option = ":" word ("-" word)*
20word = ALPHA +
21extension = ( ALPHA / DIGIT )+
8f9d1d4d
DC
22```
23
24## Order
25
26The script names MUST appear in the package.json file in alphabetical order. The other conventions outlined in this document ensure that alphabetical order will coincide with logical groupings.
27
28## Main Script Names
29
30With the exception of [npm life cycle scripts](https://docs.npmjs.com/cli/v8/using-npm/scripts#life-cycle-scripts) all script names MUST begin with one of the following names.
31
32### Build
33
34Scripts that generate a set of files from source code and / or data MUST have names that begin with `build`.
35
36If a package contains any `build:*` scripts, there MAY be a script named `build`. If so, SHOULD produce the same output as running each of the `build` scripts individually. It MUST produce a subset of the output from running those scripts.
37
f2a92ac6
DC
38### Release
39
40Scripts that have public side effects (publishing the web site, committing to Git, etc.) MUST begin with `release`.
41
8f9d1d4d
DC
42### Lint
43
44Scripts that statically analyze files (mostly, but not limited to running `eslint` itself) MUST have names that begin with `lint`.
45
46If a package contains any `lint:*` scripts, there SHOULD be a script named `lint` and it MUST run all of the checks that would have been run if each `lint:*` script was called individually.
47
48If fixing is available, a linter MUST NOT apply fixes UNLESS the script contains the `:fix` modifier (see below).
49
50### Start
51
52A `start` script is used to start a server. As of this writing, no ESLint package has more than one `start` script, so there's no need `start` to have any modifiers.
53
54### Test
55
56Scripts that execute code in order to ensure the actual behavior matches expected behavior MUST have names that begin with `test`.
57
58If a package contains any `test:*` scripts, there SHOULD be a script named `test` and it MUST run of all of the tests that would have been run if each `test:*` script was called individually.
59
60A test script SHOULD NOT include linting.
61
62A test script SHOULD report test coverage when possible.
63
64## Modifiers
65
66One or more of the following modifiers MAY be appended to the standard script names above. If a target has modifiers, they MUST be in the order in which they appear below (e.g. `lint:fix:js:watch` not `lint:watch:js:fix`)
67
68### Fix
69
70If it's possible for a linter to fix problems that it finds, add a copy of the script with `:fix` appended to the end that also fixes.
71
72### Target
73
74The name of the target of the action being run. In the case of a `build` script, it SHOULD identify the build artifact(s), e.g. "javascript" or "css" or "website". In the case of a `lint` or `test` script, it SHOULD identify the item(s) being linted or tested. In the case of a `start` script, it SHOULD identify which server is starting.
75
76A target MAY refer to a list of affected file extensions (such as `cjs` or `less`) delimited by a `+`. If there is more than one extension, the list SHOULD be alphabetized. When a file extension has variants (such as `cjs` for CommonJS and `mjs` for ESM), the common part of the extension MAY be used instead of explicitly listing out all of the variants (e.g. `js` instead of `cjs+jsx+mjs`).
77
78The target SHOULD NOT refer to name of the name of the tool that's performing the action (`eleventy`, `webpack`, etc.)
79
80### Options
81
82Additional options that don't fit under the other modifiers.
83
84### Watch
85
86If a script watches the filesystem and responds to changes, add `:watch` to the script name.