Skip to content

Commit

Permalink
enable eslint for one particular rule (#6611)
Browse files Browse the repository at this point in the history
So, Node requires generated ESM JS files need to have imports that end
with `.js` (unless they are importing the root or declared export from a
package... but for relative paths, this is a must). But we haven't quite
figured out a way to get tsc to force us to do this... so if we mess it
up, we only find out at runtime when trying to run a built ESM package.
This doesn't even necessarily show up in our tests (Jest does its own
thing a lot), and the new smoke-test doesn't cover all of our codebase.

So we set up eslint with a particular rule that looks for this. As it
happens, this rule doesn't check `import type`
(import-js/eslint-plugin-import#2270) but
fortunately `import type` doesn't matter to Node.

We don't generally enable eslint: there are plenty of rules that we
don't pass currently. We can consider adding some rules later as they
are found to be valuable. For now we just run this one rule!
  • Loading branch information
glasser authored Jun 24, 2022
1 parent db0dcaa commit 55ab60a
Show file tree
Hide file tree
Showing 11 changed files with 2,406 additions and 60 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ jobs:
- setup-node
- run: npm run prettier-check

ESLint:
docker:
- image: cimg/base:stable
steps:
- setup-node
- run: npm run lint

Spell check:
docker:
- image: cimg/base:stable
Expand Down Expand Up @@ -96,5 +103,6 @@ workflows:
- "18"
- "Check for FIXM\x45"
- Prettier
- ESLint
- Spell check
- Smoke test built package
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
generated
smoke-test
16 changes: 16 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import'],
extends: ['plugin:import/typescript'],
overrides: [
{
// Enable import/extensions on all TS files because our ESM builds require
// you to specify local imports as full paths with extensions. We don't
// need this on tests because Jest doesn't require it.
files: ['**/*.ts'],
excludedFiles: '**/__tests__/**/*.ts',
rules: { 'import/extensions': ['error', 'ignorePackages'] },
},
],
};
Loading

0 comments on commit 55ab60a

Please sign in to comment.