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

Add ESLint plugin to workaround lack of tsc support #172

Open
DelliriumX opened this issue Nov 16, 2022 · 5 comments
Open

Add ESLint plugin to workaround lack of tsc support #172

DelliriumX opened this issue Nov 16, 2022 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@DelliriumX
Copy link

Describe the bug
I have a project that uses this plugin and ts, as well as eslint with an extensive ruleset.
For some reason I keep getting linting errors. Does this plugin not have eslint support?

image

.tsconfig.json

{
  "compilerOptions": {
    "plugins": [{
      "name": "typescript-plugin-css-modules",
      "options": {
        "classnameTransform": "camelCaseOnly",
      }
    }],
    "newLine": "CRLF",
    "noEmit": true,
    "sourceMap": true,
    "target": "ES5",
    "jsx": "preserve",
    "lib": ["DOM", "WebWorker", "DOM.Iterable", "ESNext"],
    "module": "ES6",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "incremental": true,
    "skipLibCheck": true,
    "allowJs": true,
    "checkJs": true,
    "experimentalDecorators": true,
    "strict": true,
    "noImplicitAny": false,
    "noImplicitThis": false,
    "noImplicitReturns": true,
    "useUnknownInCatchVariables": true,
    "noPropertyAccessFromIndexSignature": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": false
  },
  "watchOptions": {
    "excludeDirectories": ["**/node_modules", "_build"]
  },
  "include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx", "src/types/.d.ts"],
  "exclude": ["node_modules", "_build"]
}
`
@DelliriumX
Copy link
Author

I've managed to resolve this issue but it caused a different issue instead. By adding the custom definitions as per the instructions that react-scripts users can skip, now the linter recognizes these imports as non-any but rather a properly shaped objects... however now the compiler demands these fields be accessed via index key.

image

@DelliriumX
Copy link
Author

DelliriumX commented Nov 16, 2022

By disabling the noPropertyAccessFromIndexSignature rule in the .tsconfig.json I got this to work but this is not really an ideal solution, seeing as I'd generally want that TS rule active. Initially my issue was probably related to the fact that I didn't setup the type definitions for .module.css as a global module declaration, as per the instructions. But having that setup makes this conflict with the tsconfig.json. Anyone got a better idea? The plugin itself works as far as IDE is concerned, its just that ESLint doesn't recognize imports as anything other than wait for it..... => any

@mrmckeb
Copy link
Owner

mrmckeb commented Nov 22, 2022

Hi @DelliriumX, we've been talking about shipping an ESLint plugin as a part of this plugin (if possible). Do you think that would help?

Unfortunately, there's a restriction in TypeScript which means that plugins are only run in the language service for VSCode, not outside of the IDE.

See: typescript-eslint/typescript-eslint#3645

@mrmckeb mrmckeb added the enhancement New feature or request label Nov 22, 2022
@durandj
Copy link

durandj commented Nov 30, 2022

@mrmckeb that would certainly help from my perspective!

@mrmckeb mrmckeb self-assigned this Feb 18, 2023
@mrmckeb mrmckeb changed the title eslint + ts issue. eslint sees the import as "any", even though VSCode clearly shows a string Add ESLint plugin to workaround lack of tsc support Feb 18, 2023
@jordanmnunez
Copy link

@mrmckeb +1 to eslint plugin support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants