40

In package.json I have this script name with two words lint and fix. How should I make a right name?

There are options:

  1. lowerCamelCase - lintFix
  2. UpperCamelCase - LintFix
  3. snake_case - lint_fix
  4. kebab-case - lint-fix
  5. gulp-style with a colon delimiter - lint:fix
  6. Any another delimiter.

What option is right? And why?

galkin
  • 5,264
  • 3
  • 34
  • 51

4 Answers4

22

Please always use kebab case. The colon is a throwback to gulp, and it looks terrible. I hate it.

Disclaimer: My opinions are often wrong.

thiagowfx
  • 4,832
  • 6
  • 37
  • 51
John Henckel
  • 10,274
  • 3
  • 79
  • 79
20

There is no official naming convention. Before npm@v4 standard scripts had only one word, for example test, start, prestart. npm@v4 introduced a new script prepublishOnly*.

So now, the best practice is use lowerCamelCase.

*Reference: https://iamakulov.com/notes/npm-4-prepublish/

friederbluemle
  • 33,549
  • 14
  • 108
  • 109
galkin
  • 5,264
  • 3
  • 34
  • 51
  • Any reference for this? – carraua Jun 19 '19 at 09:48
  • 1
    https://www.dropbox.com/s/2kd0v71xto2mbaj/Screenshot%202019-12-31%2006.04.33.png?dl=0 `-` appears to be the 'norm' now. `:` for some select cases. As with most things in JS, this sort of thing can vary and is based on 'style guides' for organization/individual. – CodeFinity Dec 31 '19 at 12:06
15

Looking at npm itself, as in galkin's answer, seems like a good idea. But ironically, while the npm script prepublishOnly is lowerCamelCase, most scripts in the npm GitHub project are in kebab-case: https://github.com/npm/cli/blob/latest/package.json.

One may also want to look at the most depended-on npm packages: https://www.npmjs.com/browse/depended. Many of the top packages there use kebab case, with the notable exception of lodash, which uses colons.

Update: There is also a convenience aspect which can matter more than one might think: it is more pleasant to type delimiters that don't need the shift key. At least on US, UK, and German keyboards, this too speaks for kebab-case.

Carsten Führmann
  • 3,119
  • 4
  • 26
  • 24
8

You can use a mix of both dash and colon. Dash for chaining words, colon for grouping similar scripts. Example:

  • lint:check
  • lint:fix:all
  • lint:fix:staged-only
Yanfeng Liu
  • 549
  • 5
  • 10