Skip to content

npm-package-json-lint

GitHub stars GitHub release (latest SemVer) GitHub last commit GitHub commit activity GitHub contributors

npm-package-json-lint documentation

npm-package-json-lint - GitHub

Configuration in MegaLinter

Variable Description Default value
JSON_NPM_PACKAGE_JSON_LINT_ARGUMENTS User custom arguments to add in linter CLI call
Ex: -s --foo "bar"
JSON_NPM_PACKAGE_JSON_LINT_COMMAND_REMOVE_ARGUMENTS User custom arguments to remove from command line before calling the linter
Ex: -s --foo "bar"
JSON_NPM_PACKAGE_JSON_LINT_FILE_EXTENSIONS Allowed file extensions. "*" matches any extension, "" matches empty extension. Empty list excludes all files
Ex: [".py", ""]
[".json"]
JSON_NPM_PACKAGE_JSON_LINT_FILE_NAMES_REGEX File name regex filters. Regular expression list for filtering files by their base names using regex full match. Empty list includes all files
Ex: ["Dockerfile(-.+)?", "Jenkinsfile"]
["package\\.json"]
JSON_NPM_PACKAGE_JSON_LINT_PRE_COMMANDS List of bash commands to run before the linter None
JSON_NPM_PACKAGE_JSON_LINT_POST_COMMANDS List of bash commands to run after the linter None
JSON_NPM_PACKAGE_JSON_LINT_UNSECURED_ENV_VARIABLES List of env variables explicitly not filtered before calling JSON_NPM_PACKAGE_JSON_LINT and its pre/post commands None
JSON_NPM_PACKAGE_JSON_LINT_CONFIG_FILE npm-package-json-lint configuration file nameUse LINTER_DEFAULT to let the linter find it .npmpackagejsonlintrc.json
JSON_NPM_PACKAGE_JSON_LINT_RULES_PATH Path where to find linter configuration file Workspace folder, then MegaLinter default rules
JSON_NPM_PACKAGE_JSON_LINT_DISABLE_ERRORS Run linter but consider errors as warnings false
JSON_NPM_PACKAGE_JSON_LINT_DISABLE_ERRORS_IF_LESS_THAN Maximum number of errors allowed 0
JSON_NPM_PACKAGE_JSON_LINT_CLI_EXECUTABLE Override CLI executable ['npmPkgJsonLint']

MegaLinter Flavours

This linter is available in the following flavours

Flavor Description Embedded linters Info
all Default MegaLinter Flavor 125 Docker Image Size (tag) Docker Pulls
cupcake MegaLinter for the most commonly used languages 84 Docker Image Size (tag) Docker Pulls
dotnet Optimized for C, C++, C# or VB based projects 63 Docker Image Size (tag) Docker Pulls
dotnetweb Optimized for C, C++, C# or VB based projects with JS/TS 72 Docker Image Size (tag) Docker Pulls
javascript Optimized for JAVASCRIPT or TYPESCRIPT based projects 61 Docker Image Size (tag) Docker Pulls
salesforce Optimized for Salesforce based projects 56 Docker Image Size (tag) Docker Pulls

Behind the scenes

How are identified applicable files

  • Activated only if one of these files is found: package.json
  • File extensions: .json
  • File names (regex): package\.json

How the linting is performed

npm-package-json-lint is called once on the whole project directory (project CLI lint mode)

  • filtering can not be done using MegaLinter configuration variables,it must be done using npm-package-json-lint configuration or ignore file (if existing)
  • VALIDATE_ALL_CODEBASE: false doesn't make npm-package-json-lint analyze only updated files

Example calls

npmPkgJsonLint .
npmPkgJsonLint --configFile .npmpackagejsonlintrc.json .

Help content


  Configurable linter for package.json files.

  Usage
    $ npmPkgJsonLint <patterns>

  Options
    --quiet, -q Report errors only
    --noConfigFiles, -ncf Disables use of .npmpackagejsonlintrc.json files, npmpackagejsonlint.config.js files, and npmpackagejsonlint object in package.json file.
    --configFile, -c File path of .npmpackagejsonlintrc.json
    --ignorePath, -i Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). By default, npm-package-json-lint looks for .npmpackagejsonlintignore in process.cwd().
    --maxWarnings, -mw Maximum number of warnings that can be detected before an error is thrown.
    --allowEmptyTargets Do not throw an error when a list of targets is empty.

  Examples
    $ npmPkgJsonLint --version
    $ npmPkgJsonLint .
    $ npmPkgJsonLint ./packages
    $ npmPkgJsonLint ./package1 ./package2
    $ npmPkgJsonLint -c ./config/.npmpackagejsonlintrc.json .
    $ npmPkgJsonLint --configFile ./config/npmpackagejsonlint.config.json .
    $ npmPkgJsonLint -q .
    $ npmPkgJsonLint --quiet ./packages
    $ npmPkgJsonLint . --ignorePath .gitignore
    $ npmPkgJsonLint . -i .gitignore
    $ npmPkgJsonLint . --maxWarnings 10
    $ npmPkgJsonLint . -mw 10

Installation on mega-linter Docker image