From 25b1f3d6be6a5c113a0d3224dcf13249733af36e Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 25 Jul 2020 19:37:31 +0200 Subject: [PATCH 1/3] [test] Lint JSON --- .circleci/config.yml | 3 +++ package.json | 6 ++++-- scripts/jsonlint.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 scripts/jsonlint.js diff --git a/.circleci/config.yml b/.circleci/config.yml index 8b9ee59849e1..caaff971d2cb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,6 +64,9 @@ jobs: - run: name: Lint command: yarn lint:ci + - run: + name: Lint JSON + command: yarn --silent jsonlint workflows: version: 2 pipeline: diff --git a/package.json b/package.json index 59da6daa2234..44f3a2ac2034 100644 --- a/package.json +++ b/package.json @@ -47,14 +47,16 @@ }, "scripts": { "deduplicate": "node scripts/deduplicate.js", + "jsonlint": "node scripts/jsonlint.js", "hoist": "lerna bootstrap --hoist", "bootstrap": "lerna bootstrap", "build": "lerna run build --stream", "start": "lerna run start --parallel", "prettier": "node ./scripts/prettier.js", "test": "lerna run test --parallel", - "lint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx", - "lint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx" + "lint": "yarn eslint && yarn jsonlint", + "eslint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx", + "eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx" }, "setupFiles": [ "/src/setupTests.js" diff --git a/scripts/jsonlint.js b/scripts/jsonlint.js new file mode 100644 index 000000000000..697059d2d287 --- /dev/null +++ b/scripts/jsonlint.js @@ -0,0 +1,44 @@ +/* eslint-disable no-console */ +const chalk = require('chalk'); +const fse = require('fs-extra'); +const glob = require('glob-gitignore'); +const path = require('path'); + +const passMessage = (message) => `✓ ${chalk.gray(message)}`; +const failMessage = (message) => `✗ ${chalk.whiteBright(message)}`; + +async function run() { + const workspaceRoot = path.resolve(__dirname, '..'); + + const eslintignoreContent = await fse.readFile(path.join(workspaceRoot, '.eslintignore'), { + encoding: 'utf8', + }); + const eslintignore = eslintignoreContent.split(/\r?\n/).slice(0, -1); + + const filenames = glob.sync('**/*.json', { + cwd: workspaceRoot, + ignore: [...eslintignore, 'tsconfig*.json', 'tslint.json'], + }); + + let passed = true; + const checks = filenames.map(async (filename) => { + const content = await fse.readFile(path.join(workspaceRoot, filename), { encoding: 'utf8' }); + try { + JSON.parse(content); + console.log(passMessage(filename)); + } catch (error) { + passed = false; + console.error(failMessage(`Error parsing ${filename}:\n\n${String(error)}`)); + } + }); + + await Promise.all(checks); + if (passed === false) { + throw new Error('At least one file did not pass. Check the console output'); + } +} + +run().catch((error) => { + console.error(error); + process.exit(1); +}); From 8c39c1142ab6ba252c309fbeac0d9a407578ea58 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Mon, 27 Jul 2020 22:10:35 +0200 Subject: [PATCH 2/3] remove silence --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index caaff971d2cb..a3199338c05c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,7 +66,7 @@ jobs: command: yarn lint:ci - run: name: Lint JSON - command: yarn --silent jsonlint + command: yarn jsonlint workflows: version: 2 pipeline: From a33e745734b5f60bae07518dd8f4f828276a58e5 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Mon, 27 Jul 2020 22:11:28 +0200 Subject: [PATCH 3/3] eslint now --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a3199338c05c..25ac5ff333ce 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -62,8 +62,8 @@ jobs: name: '`yarn prettier` changes committed?' command: yarn prettier check-changed - run: - name: Lint - command: yarn lint:ci + name: Eslint + command: yarn eslint:ci - run: name: Lint JSON command: yarn jsonlint