Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Lint JSON #108

Merged
merged 3 commits into from
Jul 28, 2020
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
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ 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
workflows:
version: 2
pipeline:
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@
},
"scripts": {
"deduplicate": "node scripts/deduplicate.js",
"jsonlint": "node scripts/jsonlint.js",
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
"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",
Copy link
Member Author

@oliviertassinari oliviertassinari Jul 27, 2020

Choose a reason for hiding this comment

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

We need to add stylelint later on in the CI, adding it to the list, #37

Copy link
Member

Choose a reason for hiding this comment

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

I've added stylelint in xgrid-modules, maybe we can scale it to the repo... 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe, the reason I didn't spend time on it, so far, is because it's still unclear if we will need it.

  1. We need it now
  2. Short term, we won't with core's CSS-in-JS solution (eslint is enough to lint the styles, not need for stylelint)
  3. Long term, we might switch to the CSS syntax.

"eslint": "eslint . --cache --report-unused-disable-directives --ext .js,.ts,.tsx",
"eslint:ci": "eslint . --report-unused-disable-directives --ext .js,.ts,.tsx"
},
"setupFiles": [
"<rootDir>/src/setupTests.js"
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 = (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);
});