Skip to content

uses allowed namespace

Moritz Jacobs edited this page Jun 13, 2022 · 6 revisions

uses-allowed-namespace

This rule is fixable ✓

Why?

Using namespaced script names improves readability and makes the intent more obvious.

How?

What is a namespace?

Namespace means, that scripts that belong together should be prefixed with a common name. We use : as a namespace seperator, like this:

test:lint
test:unit:watch
test:unit:coverage

Such names can be arbitrarily long, but it is rare to see more than 3 levels.

Of course you can use hooks triggered by such scripts:

{
    "build:css": "...",
    "prebuild:css": "...",
}

scriptlint predefines a few namespaces, we call these categories:

Categories

To better signify, what purpose a script has, prefix it with one of these categories:

  • build
  • dev
  • format
  • lint
  • other
  • report
  • script
  • setup
  • start
  • test

So for example a script that runs unit tests should be called test:unit.

Of course category names themselves can (sometimes must) be script names! For example build or test. In those cases they often serve as subscripts (use npm-run-all or similar!) – this is great practice!

You can also use more then one cateogry and/or subcategory. This is rare, but sometimes something like test:unit:watch:all comes in handy.

Anything that doesn't fit in these categories can go in other.

Examples

{
    "test:unit": "jest",
    "test:coverage": "jest --coverage",
    "test:lint": "eslint ./src",
    
    "format": "run-s format:eslint format:prettier",
    "format:eslint": "eslint ./src --fix",
    "format:prettier": "prettier --write src/*.js",
    
    "build": "run-s build:clean build:ts",
    "build:clean": "rimraf ./dist",
    "build:ts": "tsc -p tsconfig.json",
    
    "other:selfupdate": "updtr",
    …
}

Fixing

This rule's autofix will prepend every script without a category with other:.