Skip to content

Commit

Permalink
Add @wordpress/npm-package-json-lint-config package (#119)
Browse files Browse the repository at this point in the history
* Add `@wordpress/npm-package-json-lint-config` package

* Standardize packages `package.json` format per `@wordpress/npm-package-json-lint`

* Add unused `npm-package-json-lint` rules for reference

* Update `npm-package-json-lint` to `3.0.0-alpha3`

* Add `valid-values-publishConfig` rule with `{"access": "public"}` option for _packages_ repo

* use tabs for indentation

* Update npm-package-json-lint to v3

* Update npmPackageJsonLintConfig config formatting

* Use latest `3.0.1` npm-package-json-lint release and remove `.npmpackagejsonlintrc.json`

* Use `lint:pkg-json` as the npmPkgJsonLint script task name

* fix `pretest` test script command

* Npm package.json lint config: address my own comments

* Add is-plain-object as devDependency
  • Loading branch information
ntwb authored and gziolo committed May 17, 2018
1 parent 8a2dea2 commit 240be25
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 20 deletions.
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
"check-node-version": "^3.1.1",
"codecov": "^2.3.1",
"glob": "^7.1.2",
"is-plain-obj": "^1.1.0",
"lerna": "^2.9.0",
"mkdirp": "^0.5.1",
"npm-package-json-lint": "^3.0.1",
"npm-run-all": "^4.1.2",
"path-type": "^3.0.0",
"rimraf": "^2.6.1",
Expand All @@ -27,14 +29,36 @@
],
"preset": "@wordpress/jest-preset-default"
},
"npmPackageJsonLintConfig": {
"extends": "@wordpress/npm-package-json-lint-config",
"rules": {
"require-publishConfig": "error",
"valid-values-author": [
"error",
[
"WordPress"
]
],
"valid-values-publishConfig": [
"error",
[
{
"access": "public"
}
]
]
}
},
"scripts": {
"build-clean": "rimraf ./packages/*/build ./packages/*/build-module",
"prebuild": "npm-run-all check-engines build-clean",
"build": "node ./scripts/build.js",
"check-engines": "check-node-version --package",
"create-symlinks": "node ./scripts/create-symlinks.js",
"lerna-bootstrap": "lerna bootstrap --hoist",
"lint:pkg-json": "npmPkgJsonLint ./packages",
"postinstall": "npm-run-all lerna-bootstrap create-symlinks build",
"pretest": "npm run lint:pkg-json",
"test": "wp-scripts test-unit-js",
"test:coverage": "npm run test -- --coverage",
"test:coverage-ci": "npm run test -- --coverage && codecov",
Expand Down
6 changes: 3 additions & 3 deletions packages/babel-plugin-makepot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"publishConfig": {
"access": "public"
},
"dependencies": {
"gettext-parser": "^1.3.1",
"lodash": "^4.17.5"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-traverse": "^6.26.0"
},
"publishConfig": {
"access": "public"
}
}
2 changes: 1 addition & 1 deletion packages/browserslist-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
},
"main": "index.js",
"engines": {
"node": ">=8"
},
"main": "index.js",
"devDependencies": {
"browserslist": "^3.1.0"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/custom-templated-path-webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"webpack",
"webpack-plugin"
],
"homepage": "https://github.com/WordPress/packages/tree/master/packages/custom-templated-path-webpack-plugin/",
"homepage": "https://github.com/WordPress/packages/blob/master/packages/custom-templated-path-webpack-plugin/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/packages.git"
Expand All @@ -18,9 +18,6 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"publishConfig": {
"access": "public"
},
"dependencies": {
"escape-string-regexp": "^1.0.5"
},
Expand All @@ -29,5 +26,8 @@
},
"peerDependencies": {
"webpack": "^4.0.0"
},
"publishConfig": {
"access": "public"
}
}
8 changes: 4 additions & 4 deletions packages/i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
},
"main": "build/index.js",
"module": "build-module/index.js",
"publishConfig": {
"access": "public"
"bin": {
"pot-to-php": "./tools/pot-to-php.js"
},
"dependencies": {
"gettext-parser": "^1.3.1",
"jed": "^1.1.1",
"lodash": "^4.17.5",
"memize": "^1.0.5"
},
"bin": {
"pot-to-php": "./tools/pot-to-php.js"
"publishConfig": {
"access": "public"
}
}
4 changes: 2 additions & 2 deletions packages/jest-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
},
"main": "build/index.js",
"module": "build-module/index.js",
"files": [
"build",
"build-module"
],
"main": "build/index.js",
"module": "build-module/index.js",
"dependencies": {
"jest-matcher-utils": "^22.4.0",
"lodash": "^4.17.4"
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-preset-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
},
"main": "index.js",
"files": [
"scripts",
"jest-preset.json"
],
"main": "index.js",
"dependencies": {
"@wordpress/jest-console": "^1.0.6",
"babel-jest": "^22.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/npm-package-json-lint-config/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
65 changes: 65 additions & 0 deletions packages/npm-package-json-lint-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# `@wordpress/npm-package-json-lint-config`

> WordPress [npm-package-json-lint](https://github.com/tclindner/npm-package-json-lint) shareable config
## Installation

Install the module

```shell
$ npm install @wordpress/npm-package-json-lint-config
```

## Usage

Add this to your `package.json` file:

```json
"npmPackageJsonLintConfig": {
"extends": "@wordpress/npm-package-json-lint-config",
},
```

Or to a `.npmpackagejsonlintrc.json` file in the root of your repo:
```json
{
"extends": "@wordpress/npm-package-json-lint-config",
}

```

To add, modify, or override any [npm-package-json-lint](https://github.com/tclindner/npm-package-json-lint/wiki) rules add this to your `package.json` file:

```json
"npmPackageJsonLintConfig": {
"extends": "@wordpress/npm-package-json-lint-config",
"rules": {
"valid-values-author": [
"error",
[
"WordPress"
]
]
}
},
```

Or to a `.npmpackagejsonlintrc.json` file in the root of your repo:

```json
{
"extends": "@wordpress/npm-package-json-lint-config",
"rules": {
"require-publishConfig": "error",
"valid-values-author": [
"error",
[
"WordPress"
]
]
}
}

```

<br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
111 changes: 111 additions & 0 deletions packages/npm-package-json-lint-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
'use strict';

const defaultConfig = {
rules: {
'bin-type': 'error',
'bundledDependencies-type': 'error',
'config-type': 'error',
'cpu-type': 'error',
'dependencies-type': 'error',
'description-type': 'error',
'devDependencies-type': 'error',
'directories-type': 'error',
'engines-type': 'error',
'files-type': 'error',
'homepage-type': 'error',
'keywords-type': 'error',
'license-type': 'error',
'main-type': 'error',
'man-type': 'error',
'name-format': 'error',
'name-type': 'error',
'no-restricted-dependencies': 'off',
'no-restricted-devDependencies': 'off',
'no-restricted-pre-release-dependencies': 'off',
'no-restricted-pre-release-devDependencies': 'off',
'optionalDependencies-type': 'error',
'os-type': 'error',
'peerDependencies-type': 'error',
'prefer-absolute-version-dependencies': 'off',
'prefer-absolute-version-devDependencies': 'off',
'prefer-alphabetical-bundledDependencies': 'error',
'prefer-alphabetical-dependencies': 'error',
'prefer-alphabetical-devDependencies': 'error',
'prefer-alphabetical-optionalDependencies': 'error',
'prefer-alphabetical-peerDependencies': 'error',
'prefer-caret-version-dependencies': 'off',
'prefer-caret-version-devDependencies': 'off',
'prefer-no-engineStrict': 'off',
'prefer-no-version-zero-dependencies': 'off',
'prefer-no-version-zero-devDependencies': 'off',
'prefer-property-order': [
'error',
[
'name',
'version',
'description',
'author',
'license',
'keywords',
'homepage',
'repository',
'bugs',
'engines',
'directories',
'files',
'main',
'module',
'bin',
'dependencies',
'devDependencies',
'peerDependencies',
'publishConfig',
'scripts',
],
],
'prefer-tilde-version-dependencies': 'off',
'prefer-tilde-version-devDependencies': 'off',
'preferGlobal-type': 'error',
'private-type': 'error',
'repository-type': 'error',
'require-author': 'error',
'require-bin': 'off',
'require-bugs': 'error',
'require-bundledDependencies': 'off',
'require-config': 'off',
'require-contributors': 'off',
'require-cpu': 'off',
'require-dependencies': 'off',
'require-description': 'error',
'require-devDependencies': 'off',
'require-directories': 'off',
'require-engines': 'off',
'require-files': 'off',
'require-homepage': 'error',
'require-keywords': 'error',
'require-license': 'error',
'require-main': 'off',
'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': 'off',
'require-version': 'error',
'scripts-type': 'error',
'valid-values-author': 'off',
'valid-values-license': [ 'error', [
'GPL-2.0-or-later',
] ],
'valid-values-private': 'off',
'version-format': 'error',
'version-type': 'error',
},
};

module.exports = defaultConfig;
33 changes: 33 additions & 0 deletions packages/npm-package-json-lint-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@wordpress/npm-package-json-lint-config",
"version": "0.1.0",
"description": "WordPress npm-package-json-lint shareable config",
"author": "WordPress",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"npm-package-json-lint",
"npm-package-json-lint-config"
],
"homepage": "https://github.com/WordPress/packages/tree/master/packages/npm-package-json-lint-config/README.md",
"repository": {
"type": "git",
"url": "git+https://github.com/WordPress/packages.git"
},
"bugs": {
"url": "https://github.com/WordPress/packages/issues"
},
"main": "index.js",
"devDependencies": {
"is-plain-obj": "^1.1.0"
},
"peerDependencies": {
"npm-package-json-lint": ">= 3.0.0"
},
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "echo \"Error: run tests from root\" && exit 1"
}
}
19 changes: 19 additions & 0 deletions packages/npm-package-json-lint-config/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* External dependencies
*/
import isPlainObj from 'is-plain-obj';

/**
* Internal dependencies
*/
import config from '../';

describe( 'npm-package-json-lint config tests', () => {
it( 'should be an object', () => {
expect( isPlainObj( config ) ).toBeTruthy();
} );

it( 'should be an object', () => {
expect( isPlainObj( config.rules ) ).toBeTruthy();
} );
} );
Loading

0 comments on commit 240be25

Please sign in to comment.