Skip to content
This repository has been archived by the owner on Jul 9, 2018. It is now read-only.

Add @wordpress/npm-package-json-lint-config package #119

Merged
merged 14 commits into from
May 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
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be defined as a devDependencies in the root if we're not using it in the root?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package are local, tests are global, so we just need pick one approach for those dependencies. I have a feeling that other packages define them in their own package.json file. Lerna will hoist, them so we don't need it in here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. Seemed we should need it to be defined in either root or npm-package-json-lint-config/package.json, but not both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, one of them is enough.

"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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Not sure if introduction of dependency here is strictly necessary. What is it we're testing?

Would expect.toMatchObject( {} ) have been adequate, particularly if we don't care about subset of properties?

Alternatively, Lodash includes an _.isPlainObject as well, if we want to lean on Lodash as a canonical source of utility functions.

Thinking in terms of being explicit with where dependencies add value to avoid excessive proliferation.


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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toBeTruthy assertion should be discouraged, as it implies that we expect it could be a value other than explicitly true (a non-zero number, a non-empty string, etc). If we expect it should be explicitly true, we should assert as toBe( true ).

} );

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