Merge pull request #206 from babel/trailing-commas-scripts

Add --check to build-data and skip trailing-commas on scripts/*.js
This commit is contained in:
Artem Yavorsky 2017-03-14 11:49:57 +02:00 committed by GitHub
commit f9f31c2120
4 changed files with 45 additions and 18 deletions

View File

@ -25,13 +25,16 @@ install:
- $PKG_CMD install
script:
- 'if [ -n "${LINT-}" ]; then $PKG_CMD run lint ; fi'
- 'if [ -z "${LINT-}" ]; then $PKG_CMD run test-ci ; fi'
- 'if [ -n "${DATA_CHECK-}" ]; then $PKG_CMD run build-data -- --check ; fi'
- 'if [ -z "${LINT-}" ] && [ -z "${DATA_CHECK-}" ]; then $PKG_CMD run test-ci ; fi'
matrix:
fast_finish: true
include:
- node_js: "node"
env: LINT=true PKG_CMD="npm"
- node_js: "node"
env: DATA_CHECK=true PKG_CMD="npm"
exclude:
- node_js: "4"
env: PKG_CMD="yarn"
after_success: 'if [ -z "${LINT-}" ]; then npm run coverage-ci ; fi'
after_success: 'if [ -z "${LINT-}" ] && [ -z "${DATA_CHECK-}" ]; then npm run coverage-ci ; fi'

View File

@ -15,9 +15,9 @@
"coverage-ci": "nyc report --reporter=json && codecov -f coverage/coverage-final.json",
"dev": "babel -w src -d lib",
"fix": "eslint . --fix",
"format": "prettier --trailing-comma all --write \"src/*.js\" \"test/*.js\" && prettier --trailing-comma es5 --write \"scripts/*.js\"",
"lint": "eslint .",
"precommit": "lint-staged",
"prettify": "prettier --trailing-comma all --write \"src/*.js\" \"scripts/*.js\" \"test/*.js\"",
"test": "npm run build && npm run test-only",
"test-ci": "nyc npm run test",
"test-only": "mocha ./test --compilers js:babel-register -t 10000"
@ -106,10 +106,14 @@
"sourceMap": false
},
"lint-staged": {
"{src,scripts}/**/*.js": [
"src/**/*.js": [
"prettier --trailing-comma all --write",
"git add"
],
"scripts/*.js": [
"prettier --trailing-comma es5 --write",
"git add"
],
"test/*.js": [
"prettier --trailing-comma all --write",
"git add"

View File

@ -5,6 +5,7 @@ const path = require("path");
const flatten = require("lodash/flatten");
const flattenDeep = require("lodash/flattenDeep");
const isEqual = require("lodash/isEqual");
const mapValues = require("lodash/mapValues");
const pluginFeatures = require("../data/plugin-features");
const builtInFeatures = require("../data/built-in-features");
@ -53,7 +54,7 @@ const envMap = {
const invertedEqualsEnv = Object.keys(envs).filter(b => envs[b].equals).reduce((
a,
b,
b
) => {
const checkEnv = envMap[envs[b].equals] || envs[b].equals;
environments.some(env => {
@ -87,7 +88,7 @@ const compatibilityTests = flattenDeep(
return test.subtests
? [test, renameTests(test.subtests, name => test.name + " / " + name)]
: test;
})),
}))
);
const getLowestImplementedVersion = ({ features }, env) => {
@ -114,7 +115,7 @@ const getLowestImplementedVersion = ({ features }, env) => {
res: test.res,
isBuiltIn,
};
}),
})
);
const envTests = tests.map(({ res: test, name, isBuiltIn }, i) => {
@ -140,8 +141,7 @@ const getLowestImplementedVersion = ({ features }, env) => {
.filter(t => t.startsWith(env))
// Babel assumes strict mode
.filter(
test =>
tests[i].res[test] === true || tests[i].res[test] === "strict",
test => tests[i].res[test] === true || tests[i].res[test] === "strict"
)
// normalize some keys
.map(test => envMap[test] || test)
@ -197,12 +197,36 @@ const generateData = (environments, features) => {
});
};
const pluginsDataPath = path.join(__dirname, "../data/plugins.json");
const builtInsDataPath = path.join(__dirname, "../data/built-ins.json");
const newPluginData = generateData(environments, pluginFeatures);
const newBuiltInsData = generateData(environments, builtInFeatures);
if (process.argv[2] === "--check") {
const currentPluginData = require(pluginsDataPath);
const currentBuiltInsData = require(builtInsDataPath);
if (
!isEqual(currentPluginData, newPluginData) ||
!isEqual(currentBuiltInsData, newBuiltInsData)
) {
console.error(
"The newly generated plugin/built-in data does not match the current " +
"files. Re-run `npm run build-data`."
);
process.exit(1);
}
process.exit(0);
}
fs.writeFileSync(
path.join(__dirname, "../data/plugins.json"),
JSON.stringify(generateData(environments, pluginFeatures), null, 2) + "\n",
pluginsDataPath,
JSON.stringify(newPluginData, null, 2) + "\n"
);
fs.writeFileSync(
path.join(__dirname, "../data/built-ins.json"),
JSON.stringify(generateData(environments, builtInFeatures), null, 2) + "\n",
builtInsDataPath,
JSON.stringify(newBuiltInsData, null, 2) + "\n"
);

View File

@ -1843,11 +1843,7 @@ dom-serializer@0, dom-serializer@~0.1.0:
domelementtype "~1.1.1"
entities "~1.1.1"
domelementtype@1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.0.tgz#b17aed82e8ab59e52dd9c19b1756e0fc187204c2"
domelementtype@~1.1.1:
domelementtype@1, domelementtype@~1.1.1:
version "1.1.3"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.1.3.tgz#bd28773e2642881aec51544924299c5cd822185b"