Coder Social home page Coder Social logo

tanepiper / npm-lint Goto Github PK

View Code? Open in Web Editor NEW
26.0 4.0 1.0 977 KB

A linter for npm & node package.json files with a focus on dependency security

License: MIT License

JavaScript 18.97% TypeScript 81.03%
linter linting-rules npm npm-scripts nodejs security security-tools dependency-analysis

npm-lint's Introduction

npm-linter

A opinionated, but configurable linter for npm & node package.json files with a focus on security.

Github | Issues | NPM

Install

npm i -g npm-lint

npm-lint is build using Typescript on top of node 8 as it uses async/await - however the distribution is compiled and confirmed to work with node >= 6.5.0.

Please note the APIs and commands are likely to change quite a bit

What is npm-lint?

A tool that reads a .npmlint.json file in a directory and from this can parse a package.json file and enforce these rules.

It's designed to enforce rules across many repositories within your organisation. By putting a .npmlint.json file in your root directory and running npm-lint the tool will check the file to ensure it meets your configuration.

The focus is on security and being able to lock down where dependencies are resolved from, and where packages are published too and being able to implement this in pre-commit/pre-push hooks or CI environments

The currently implemented options are:

properties

An array of properties a package must include.

The name and version are hard coded these are always required, so do not need to be added to your list If your package.json does not have these fields then it will cause a failure on exit

Example

{
    "properties": {
    "private": true,
    "required": ["description", "main", "author", "license"]
  }

}

scripts

An object of properties that will handle checking the scripts property in your package.json

scripts.allow

An array of names of executables allowed to be in scripts. If a script it found to be using an application not in this list it will cause a failure on exit

Example

{
   "scripts": {
        "allow": ["node", "npm", "git"]
    }
}

dependencies

An object of properties that will handle checking the dependencies and devDependencies in your package.json

dependencies.checkLatest

A boolean value to determine if a scan of all dependencies should be done and to advise of the latest version

dependencies.sources

An array of strings that are whitelisted to be in dependencies as non-npm sources. For example if you point to a git dependency, or a private repository then these should be included. You can reference the entire source or a domain. By default this will accept any valid semver as a valid NPM source. If you use non-semver values such as release tags you also need to include them in this file

Example

{
  "dependencies": {
       "sources": [
           "release",
           "https://github.com",
           "https://git.myrepo.com/myrepo.git"
       ]
   }
}

npm-lint's People

Contributors

tanepiper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

marado

npm-lint's Issues

Make `dependencies.allow` work with dependency tree

This feature should analyse all dependencies in a package.json, but also analyse it's dependency tree.

This would be in two modes:

  • Local - Reads all package.json files within node_modules and checks them. If these dependencies contain sub-dependencies it will continue to recurse until all folders are done.
  • Remote - Reads the package.json and then uses this to resolve all dependencies remotely. It will then analyse like local, and recurse until all dependencies are resolved.

does not look in node_modules/.bin/

+ [email protected]
added 233 packages from 221 contributors in 25.222s
/src # npm-lint
Running npm-linter
Warning: No .npmlint.json found at /src; Using default settings
Error: package.json script "start" has a unknown executable "webpack-dev-server"
Error: package.json script "build" has a unknown executable "webpack"
┌────────────────┬───┐
│ Total Errors   │ 2 │
├────────────────┼───┤
│ Total Warnings │ 1 │
└────────────────┴───┘

but...

/src # ls node_modules/.bin/
acorn                 handlebars            mkdirp                sha.js                webpack
ansi-html             import-local-fixture  multicast-dns         terser                webpack-cli
atob                  json5                 rimraf                uglifyjs              webpack-dev-server
errno                 miller-rabin          semver                uuid                  which

Update Node version

Hi, would you mind if I try to setup CI to test it against newer Node version? (12 and 14 at least)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.