Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add package.json linter #304

Merged
merged 3 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ point being `src/index.js`.

All test files should be placed under `test`. Individual test files should end in `.spec.js` and setup files for the node and the browser should be `test/node.js` and `test/browser.js` respectively.

Your `package.json` should have the following entries.
Your `package.json` should have the following entries and should pass `aegir lint-package-json`.


```json
"main": "src/index.js",
"files": [
"src",
"dist"
],
"scripts": {
"lint": "aegir lint",
"release": "aegir release",
Expand Down Expand Up @@ -69,6 +73,7 @@ You can run it using

```bash
$ aegir lint
$ aegir lint-package-json
```

### Testing
Expand Down
27 changes: 27 additions & 0 deletions cmds/lint-package-json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const resolveBin = require('resolve-bin')
const execa = require('execa')
const { fromAegir, fromRoot } = require('./../src/utils')

const bin = resolveBin.sync('npm-package-json-lint', { executable: 'npmPkgJsonLint' })

module.exports = {
command: 'lint-package-json',
desc: 'Lint package.json',
handler (argv) {
const input = argv._.slice(1)
const useBuiltinConfig = !input.includes('--configFile')
const config = useBuiltinConfig
? ['-c', fromAegir('src/config/.npmpackagejsonlintrc.json')]
: []

return execa(bin, [
fromRoot('package.json'),
...config,
...input
], {
stdio: 'inherit'
})
}
}
52 changes: 29 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@
"name": "aegir",
"version": "17.1.1",
"description": "JavaScript project management",
"keywords": [
"webpack",
"standard",
"lint",
"build"
],
"homepage": "https://github.com/ipfs/aegir",
"bugs": "https://github.com/ipfs/aegir/issues",
"license": "MIT",
"leadMaintainer": "Hugo Dias <hugomrdias@gmail.com>",
"files":[
"cmds",
"src",
"cli.js"
],
"main": "cli.js",
"browser": {
"fs": false
},
"bin": {
"aegir": "cli.js"
},
"repository": "github:ipfs/aegir",
"scripts": {
"lint": "node cli.js lint",
"test:node": "cross-env AEGIR_TEST=hello node cli.js test -t node --files 'test/**/*.spec.js'",
Expand All @@ -23,13 +38,6 @@
"release-minor": "npm run test && node cli.js release --no-build --no-test --type minor",
"release-major": "npm run test && node cli.js release --no-build --no-test --type major"
},
"keywords": [
"webpack",
"standard",
"lint",
"build"
],
"license": "MIT",
"dependencies": {
"@babel/cli": "7.1.2",
"@babel/core": "7.1.2",
Expand Down Expand Up @@ -88,6 +96,7 @@
"lodash": "^4.17.11",
"mocha": "^5.2.0",
"mocha-jenkins-reporter": "~0.4.1",
"npm-package-json-lint": "^3.4.1",
"npm-which": "^3.0.1",
"nyc": "^13.1.0",
"p-map": "^2.0.0",
Expand All @@ -113,13 +122,22 @@
"yargs": "^12.0.2",
"yargs-parser": "^11.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/ipfs/aegir"
"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"mock-require": "^3.0.2",
"sinon": "^7.1.0"
},
"engines": {
"node": ">=8.0.0"
"node": ">=10.0.0",
"npm": ">=6.0.0"
},
"browserslist": [
">1%",
"last 2 versions",
"Firefox ESR",
"not ie < 11"
],
"contributors": [
"Alan Shaw <alan.shaw@protocol.ai>",
"Alan Shaw <alan@tableflip.io>",
Expand Down Expand Up @@ -149,17 +167,5 @@
"mkg20001 <mkg20001@gmail.com>",
"npmcdn-to-unpkg-bot <npmcdn-to-unpkg-bot@users.noreply.github.com>",
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victor@protocol.ai>"
],
"devDependencies": {
"chai": "^4.2.0",
"cross-env": "^5.2.0",
"mock-require": "^3.0.2",
"sinon": "^7.1.0"
},
"browserslist": [
">1%",
"last 2 versions",
"Firefox ESR",
"not ie < 11"
]
}
88 changes: 88 additions & 0 deletions src/config/.npmpackagejsonlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"rules": {
"require-author": "off",
"require-bin": "off",
"require-bugs": "error",
"require-bundledDependencies": "off",
"require-config": "off",
"require-contributors": "off",
"require-cpu": "off",
"require-dependencies": "off",
"require-description": "off",
"require-devDependencies": "off",
"require-directories": "off",
"require-engines": "error",
"require-files": "error",
"require-homepage": "error" ,
"require-keywords": "error",
"require-license": "error",
"require-main": "error",
"require-man": "off",
"require-module": "off",
"require-name": "error",
"require-optionalDependencies": "off",
"require-os": "off",
"require-peerDependencies": "off",
"require-preferGlobal": "off",
"require-private": "off",
"require-publishConfig": "off",
"require-repository": "error",
"require-scripts": "error",
"require-version": "error",
"bin-type": "error",
"files-type": "error",
"version-type": "error",
"valid-values-engines": ["error", [
{
"node": ">=10.0.0",
"npm": ">=6.0.0"
}
]],
"valid-values-license": ["error", [
"MIT"
]],
"prefer-alphabetical-dependencies": "error",
"prefer-alphabetical-devDependencies": "error",
"prefer-property-order": ["error",
[
"name",
"version",
"description",
"keywords",
"homepage",
"bugs",
"license",
"author",
"leadMaintainer",
"files",
"main",
"browser",
"module",
"jsnext:main",
"bin",
"repository",
"scripts",
"dependencies",
"devDependencies",
"peerDependencies",
"bundledDependencies",
"bundleDependencies",
"optionalDependencies",
"engineStrict",
"engines",
"pre-commit",
"types",
"typings",
"browserslist",
"browserify",
"babel",
"eslintConfig",
"stylelint",
"contributors",
"os",
"cpu",
"private",
"publishConfig"
]]
}
}