Skip to content

Commit

Permalink
feat(workspace): cross-os jsonlint
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jan 24, 2020
1 parent 1092c22 commit 8a7c288
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
command: yarn lint:ci
- run:
name: Lint JSON
command: yarn jsonlint
command: yarn --silent jsonlint
test_types:
<<: *defaults
steps:
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
"docs:typescript:formatted": "yarn workspace docs typescript:transpile",
"docs:mdicons:synonyms": "babel-node --config-file ./babel.config.js ./docs/scripts/updateIconSynonyms",
"framer:build": "yarn workspace framer build",
"jsonlint": "yarn --silent jsonlint:files | xargs -n1 jsonlint -q -c && echo \"jsonlint: no lint errors\"",
"jsonlint:files": "find . -name \"*.json\" | grep -v -f .eslintignore",
"jsonlint": "node scripts/jsonlint.js",
"lint": "eslint . --cache --report-unused-disable-directives",
"lint:ci": "eslint . --report-unused-disable-directives",
"lint:fix": "eslint . --cache --fix",
Expand Down Expand Up @@ -79,6 +78,7 @@
"babel-plugin-transform-react-remove-prop-types": "^0.4.21",
"chai": "^4.1.2",
"chai-dom": "^1.8.1",
"chalk": "^3.0.0",
"compression-webpack-plugin": "^3.0.0",
"confusing-browser-globals": "^1.0.9",
"cross-env": "^6.0.0",
Expand All @@ -102,7 +102,6 @@
"glob": "^7.1.2",
"glob-gitignore": "^1.0.11",
"jsdom": "^16.0.0",
"jsonlint": "^1.6.3",
"karma": "^4.3.0",
"karma-browserstack-launcher": "~1.4.0",
"karma-chrome-launcher": "^3.0.0",
Expand Down
44 changes: 44 additions & 0 deletions scripts/jsonlint.js
Original file line number Diff line number Diff line change
@@ -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 = chalk.gray;
const failMessage = chalk.whiteBright;

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,
});

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);
});
16 changes: 16 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,14 @@ ansi-styles@^4.0.0:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

ansi-styles@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359"
integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==
dependencies:
"@types/color-name" "^1.1.1"
color-convert "^2.0.1"

ansi-styles@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.0.0.tgz#cb102df1c56f5123eab8b67cd7b98027a0279178"
Expand Down Expand Up @@ -4228,6 +4236,14 @@ chalk@^1.0.0, chalk@^1.1.3:
strip-ansi "^3.0.0"
supports-color "^2.0.0"

chalk@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-3.0.0.tgz#3f73c2bf526591f574cc492c51e2456349f844e4"
integrity sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==
dependencies:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-0.4.0.tgz#5199a3ddcd0c1efe23bc08c1b027b06176e0c64f"
Expand Down

0 comments on commit 8a7c288

Please sign in to comment.