'Have ESLint or Prettier detect undefined / unimported code
I set up a JavaScript project with ESLint and Prettier.
Here is my .eslintrc.json:
{
"extends": [
"next/core-web-vitals",
"plugin:unicorn/recommended",
"plugin:prettier/recommended"
],
"parserOptions": {
"ecmaVersion": 2022
},
"plugins": ["simple-import-sort"],
"rules": {
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"unicorn/no-null": "off",
"unicorn/prevent-abbreviations": [
"error",
{
"allowList": {
"getServerSideProps": true,
"getStaticProps": true
}
}
]
},
"overrides": [
{
"files": ["*.spec.ts"],
"extends": ["plugin:cypress/recommended"]
}
]
}
and here is my .prettierrc.json:
{
"arrowParens": "avoid",
"bracketSameLine": false,
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxSingleQuote": false,
"printWidth": 80,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false
}
Now I wrote this test:
import { describe } from 'riteway';
describe('mapUserSessionToUserProfile()', async assert => {
const email = '[email protected]';
const session = {
email,
issuer: 'did:example:123456789abcdefghi',
publicAddress: '0xDC25EF3F5B8A186998338A2ADA83795FBA2D695E',
};
const userProfile = { email, id: session.issuer };
assert({
given: 'a user session',
should: 'return a user profile',
actual: mapUserSessionToUserProfile(session),
expected: userProfile,
});
});
but as you can see, I forgot to:
import { mapUserSessionToUserProfile } from './user-profile-helpers';
ESLint didn't complain. I was wondering, is there a way for ESLint to recognize these errors?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
