From 240be25ebe74d4842a2c2195650a9f12de67ebf6 Mon Sep 17 00:00:00 2001 From: Stephen Edgar Date: Thu, 17 May 2018 19:39:28 +1000 Subject: [PATCH] Add `@wordpress/npm-package-json-lint-config` package (#119) * 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 --- package.json | 24 ++++ packages/babel-plugin-makepot/package.json | 6 +- packages/browserslist-config/package.json | 2 +- .../package.json | 8 +- packages/i18n/package.json | 8 +- packages/jest-console/package.json | 4 +- packages/jest-preset-default/package.json | 2 +- packages/npm-package-json-lint-config/.npmrc | 1 + .../npm-package-json-lint-config/README.md | 65 ++++++++++ .../npm-package-json-lint-config/index.js | 111 ++++++++++++++++++ .../npm-package-json-lint-config/package.json | 33 ++++++ .../test/index.test.js | 19 +++ packages/wordcount/package.json | 18 ++- scripts/create-symlinks.js | 1 + 14 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 packages/npm-package-json-lint-config/.npmrc create mode 100644 packages/npm-package-json-lint-config/README.md create mode 100644 packages/npm-package-json-lint-config/index.js create mode 100644 packages/npm-package-json-lint-config/package.json create mode 100644 packages/npm-package-json-lint-config/test/index.test.js diff --git a/package.json b/package.json index cecb354e483e5a..a73923eb0e08b3 100644 --- a/package.json +++ b/package.json @@ -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", @@ -27,6 +29,26 @@ ], "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", @@ -34,7 +56,9 @@ "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", diff --git a/packages/babel-plugin-makepot/package.json b/packages/babel-plugin-makepot/package.json index 2c630df368c71c..dc86cc6eb426a1 100644 --- a/packages/babel-plugin-makepot/package.json +++ b/packages/babel-plugin-makepot/package.json @@ -19,9 +19,6 @@ }, "main": "build/index.js", "module": "build-module/index.js", - "publishConfig": { - "access": "public" - }, "dependencies": { "gettext-parser": "^1.3.1", "lodash": "^4.17.5" @@ -29,5 +26,8 @@ "devDependencies": { "babel-core": "^6.26.0", "babel-traverse": "^6.26.0" + }, + "publishConfig": { + "access": "public" } } diff --git a/packages/browserslist-config/package.json b/packages/browserslist-config/package.json index 3ab42fd1dc0d31..89c7e18287a082 100644 --- a/packages/browserslist-config/package.json +++ b/packages/browserslist-config/package.json @@ -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" }, diff --git a/packages/custom-templated-path-webpack-plugin/package.json b/packages/custom-templated-path-webpack-plugin/package.json index 362c2892d06861..71c6271f4492fc 100644 --- a/packages/custom-templated-path-webpack-plugin/package.json +++ b/packages/custom-templated-path-webpack-plugin/package.json @@ -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" @@ -18,9 +18,6 @@ }, "main": "build/index.js", "module": "build-module/index.js", - "publishConfig": { - "access": "public" - }, "dependencies": { "escape-string-regexp": "^1.0.5" }, @@ -29,5 +26,8 @@ }, "peerDependencies": { "webpack": "^4.0.0" + }, + "publishConfig": { + "access": "public" } } diff --git a/packages/i18n/package.json b/packages/i18n/package.json index bd696ed13c7fbd..b4d12b8a85da49 100644 --- a/packages/i18n/package.json +++ b/packages/i18n/package.json @@ -17,8 +17,8 @@ }, "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", @@ -26,7 +26,7 @@ "lodash": "^4.17.5", "memize": "^1.0.5" }, - "bin": { - "pot-to-php": "./tools/pot-to-php.js" + "publishConfig": { + "access": "public" } } diff --git a/packages/jest-console/package.json b/packages/jest-console/package.json index 2f1133189b84c2..165f44daf0c068 100644 --- a/packages/jest-console/package.json +++ b/packages/jest-console/package.json @@ -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" diff --git a/packages/jest-preset-default/package.json b/packages/jest-preset-default/package.json index 8408870d35162d..f623d8aada228c 100644 --- a/packages/jest-preset-default/package.json +++ b/packages/jest-preset-default/package.json @@ -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", diff --git a/packages/npm-package-json-lint-config/.npmrc b/packages/npm-package-json-lint-config/.npmrc new file mode 100644 index 00000000000000..43c97e719a5a82 --- /dev/null +++ b/packages/npm-package-json-lint-config/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/packages/npm-package-json-lint-config/README.md b/packages/npm-package-json-lint-config/README.md new file mode 100644 index 00000000000000..3cbbaae6062901 --- /dev/null +++ b/packages/npm-package-json-lint-config/README.md @@ -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" + ] + ] + } +} + +``` + +

Code is Poetry.

diff --git a/packages/npm-package-json-lint-config/index.js b/packages/npm-package-json-lint-config/index.js new file mode 100644 index 00000000000000..8b9e5dc2208a17 --- /dev/null +++ b/packages/npm-package-json-lint-config/index.js @@ -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; diff --git a/packages/npm-package-json-lint-config/package.json b/packages/npm-package-json-lint-config/package.json new file mode 100644 index 00000000000000..783eaab482eaad --- /dev/null +++ b/packages/npm-package-json-lint-config/package.json @@ -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" + } +} diff --git a/packages/npm-package-json-lint-config/test/index.test.js b/packages/npm-package-json-lint-config/test/index.test.js new file mode 100644 index 00000000000000..02494943383b71 --- /dev/null +++ b/packages/npm-package-json-lint-config/test/index.test.js @@ -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(); + } ); +} ); diff --git a/packages/wordcount/package.json b/packages/wordcount/package.json index 33a3961df39136..d92db920ccd8ff 100644 --- a/packages/wordcount/package.json +++ b/packages/wordcount/package.json @@ -1,15 +1,23 @@ { "name": "@wordpress/wordcount", "version": "1.0.2", + "description": "WordPress Word Count Utility", + "author": "WordPress", + "license": "GPL-2.0-or-later", + "keywords": [ + "wordpress", + "wordcount" + ], + "homepage": "https://github.com/WordPress/packages/tree/master/packages/wordcount/README.md", "repository": { - "type": "git", - "url": "https://github.com/WordPress/packages.git" + "type": "git", + "url": "git+https://github.com/WordPress/packages.git" + }, + "bugs": { + "url": "https://github.com/WordPress/packages/issues" }, - "description": "WordPress Word Count Utility", "main": "build/index.js", "module": "build-module/index.js", - "author": "WordPress", - "license": "GPL-2.0+", "dependencies": { "lodash": "^4.17.4" }, diff --git a/scripts/create-symlinks.js b/scripts/create-symlinks.js index cb7aabe72320be..3763df823a12e2 100644 --- a/scripts/create-symlinks.js +++ b/scripts/create-symlinks.js @@ -12,6 +12,7 @@ mkdirp( 'node_modules/@wordpress', () => { [ 'packages/browserslist-config', 'node_modules/@wordpress/browserslist-config' ], [ 'packages/babel-preset-default', 'node_modules/@wordpress/babel-preset-default' ], [ 'packages/jest-preset-default', 'node_modules/@wordpress/jest-preset-default' ], + [ 'packages/npm-package-json-lint-config', 'node_modules/@wordpress/npm-package-json-lint-config' ], [ 'packages/scripts', 'node_modules/@wordpress/scripts' ], [ 'node_modules/@wordpress/scripts/bin/wp-scripts.js', 'node_modules/.bin/wp-scripts' ], ];