Skip to content

Commit

Permalink
Make each package control its own linting.
Browse files Browse the repository at this point in the history
For now, we keep eslintrc at the very top. In the future we might do
something different (with a shared rule set at the root), maybe.

We might want to go the opposite approach: control linting always at the
top level. This is what you'd have in a large monorepo with a consistent
style guide. But eslint (especially with typescript-eslint), is brittle
when doing that; we want to lint **source** files, but not **generated**
files. ESLint also needs to be passed exactly what file(s) to operate
on. This means that we end up in an annoying place:

- ESLint needs to know what all of your source files what (vs generated
  files).
- The script calling ESLint needs to know what all of your source files
  are.

Your guess is as good as mine for why one of these isn't sufficient.
Maybe it is, but I'm doing this wrong? Or typescript-eslint makes things
harder?

But anyway, here we are. We are now in a place where a global config
needs to know about the layout of each package. This seems difficult, so
we instead delegate this task to individual packages, who actually know
their own layout.
  • Loading branch information
Eyas committed Aug 30, 2021
1 parent bb9523a commit bf75a0a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ module.exports = {
ignorePatterns: [],
parser: '@typescript-eslint/parser',
parserOptions: {
project: ['./src/tsconfig.json', './test/tsconfig.json'],
project: [
// In our schema, we run eslint from individual
// packages. I'm sure there's a better way, but
// right now just use relative path to go back
// to project root.
'../../packages/*/src/tsconfig.json',
'../../packages/*/test/tsconfig.json',
],
sourceType: 'module',
},
rules: {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"clean": "rimraf \"packages/**/dist\" \"packages/**/*.tsbuildinfo\" packages/schema-dts/lib/*",
"build": "npm run build --workspaces",
"lint:prettier": "prettier --check .",
"lint:eslint": "eslint ",
"lint:eslint": "npm run lint:eslint --workspaces --if-present --",
"lint": "npm run lint:eslint && npm run lint:prettier",
"fix:prettier": "prettier --write .",
"fix:eslint": "eslint --fix ",
"fix:eslint": "npm run lint:eslint -- --fix ",
"fix": "npm run fix:eslint && npm run fix:prettier",
"test": "npm run lint && npm run test --workspaces",
"coverage_on_travis": "npm run coverage_on_travis -w schema-dts-gen",
Expand Down
1 change: 1 addition & 0 deletions packages/schema-dts-gen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
},
"license": "Apache-2.0",
"scripts": {
"lint:eslint": "eslint src/**/*.ts test/**/*.ts",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
"prepare": "npm run build",
"build": "tsc -b"
Expand Down
1 change: 1 addition & 0 deletions packages/schema-dts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"directory": "packages/schema-dts"
},
"scripts": {
"lint:eslint": "eslint test/**/*.ts",
"prepare": "mkdirp lib/",
"build:generate": "schema-dts-gen > lib/schema.ts",
"build:compile": "tsc -p .",
Expand Down

0 comments on commit bf75a0a

Please sign in to comment.