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

"Definition for rule '@typescript/eslint/....' was not found" error happening in js, cjs and mjs files #749

Closed
JaViLuMa opened this issue Mar 17, 2024 · 5 comments

Comments

@JaViLuMa
Copy link

So I am having an issue when overriding/replacing some default rules from XO when it comes to js, cjs and mjs files.

I have the following in my .xo-config.json file:

    "@typescript-eslint/object-curly-spacing": ["error", "always"],
    "@typescript-eslint/consistent-type-imports": "error",
    "@typescript-eslint/naming-convention": [
      "error",
      {
        "format": ["PascalCase"],
        "selector": ["typeLike", "enumMember"]
      },
      {
        "custom": {
          "match": false,
          "regex": "^I[A-Z]"
        },
        "format": ["PascalCase"],
        "selector": "interface"
      }
    ]

When I come to any of the js, cjs and mjs files, this is the error I get at the beginning of the file:

Definition for rule '@typescript-eslint/object-curly-spacing' was not found. (@typescript-eslint/object-curly-spacing)XO(@typescript-eslint/object-curly-spacing)
Definition for rule '@typescript-eslint/consistent-type-imports' was not found. (@typescript-eslint/consistent-type-imports)XO(@typescript-eslint/consistent-type-imports)
Definition for rule '@typescript-eslint/naming-convention' was not found. (@typescript-eslint/naming-convention)XO(@typescript-eslint/naming-convention)

image

Any reasons why does this happen?

@simwai
Copy link

simwai commented Apr 29, 2024

+1 for @typescript-eslint/naming-convertion:

"rules": {
      "@typescript-eslint/naming-convention": [
        {
          "selector": "variableLike",
          "modifiers": [
            "private"
          ],
          "format": [
            "camelCase"
          ],
          "leadingUnderscore": "require"
        }
      ],
   }
2024-04-29 10:28:47.490 [info] [server] BaseConfig:
	Configuration for rule "@typescript-eslint/naming-convention" is invalid:
	Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '{  selector: "variableLike",  modifiers: [ "private" ],  format: [ "camelCase" ],  leadingUnderscore: "require"}').
 
2024-04-29 10:28:47.490 [info] [server] Error: BaseConfig:
	Configuration for rule "@typescript-eslint/naming-convention" is invalid:
	Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '{  selector: "variableLike",  modifiers: [ "private" ],  format: [ "camelCase" ],  leadingUnderscore: "require"}').

    at ConfigValidator.validateRuleOptions (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2048:23)
    at g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2103:18
    at Array.forEach (<anonymous>)
    at ConfigValidator.validateRules (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2100:34)
    at ConfigValidator.validateConfigArray (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2226:18)
    at CascadingConfigArrayFactory._finalizeConfigArray (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3985:23)
    at CascadingConfigArrayFactory.getConfigArrayForFile (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3791:21)
    at CLIEngine.isPathIgnored (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\lib\cli-engine\cli-engine.js:1000:18)
    at ESLint.isPathIgnored (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\lib\eslint\eslint.js:681:26)
    at Object.lintText (file:///g:/Documents/Programming/JS/Projects/smartway-website-ng/node_modules/xo/index.js:66:31) 
2024-04-29 10:28:47.504 [info] [server] BaseConfig:
	Configuration for rule "@typescript-eslint/naming-convention" is invalid:
	Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '{  selector: "variableLike",  modifiers: [ "private" ],  format: [ "camelCase" ],  leadingUnderscore: "require"}').
 
2024-04-29 10:28:47.504 [info] [server] Error: BaseConfig:
	Configuration for rule "@typescript-eslint/naming-convention" is invalid:
	Severity should be one of the following: 0 = off, 1 = warn, 2 = error (you passed '{  selector: "variableLike",  modifiers: [ "private" ],  format: [ "camelCase" ],  leadingUnderscore: "require"}').

    at ConfigValidator.validateRuleOptions (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2048:23)
    at g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2103:18
    at Array.forEach (<anonymous>)
    at ConfigValidator.validateRules (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2100:34)
    at ConfigValidator.validateConfigArray (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:2226:18)
    at CascadingConfigArrayFactory._finalizeConfigArray (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3985:23)
    at CascadingConfigArrayFactory.getConfigArrayForFile (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\node_modules\@eslint\eslintrc\dist\eslintrc.cjs:3791:21)
    at CLIEngine.isPathIgnored (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\lib\cli-engine\cli-engine.js:1000:18)
    at ESLint.isPathIgnored (g:\Documents\Programming\JS\Projects\smartway-website-ng\node_modules\eslint\lib\eslint\eslint.js:681:26)
    at Object.lintText (file:///g:/Documents/Programming/JS/Projects/smartway-website-ng/node_modules/xo/index.js:66:31) 

@spence-s
Copy link
Contributor

yes - xo applies the rules to every file, but in the case of a JS file in a typescript project, it may be better to use overrides to prevent it from trying to apply the TS rules to those files:

{
  "overrides":  [
    "files": "*.ts",
     "rules" {
       "@typescript-eslint/...": [...]
    }
  ]
}

@simwai
Copy link

simwai commented May 30, 2024

This issues is definitely not closed. This is not a fix for the problem, that it is not possible to provide the correct configuration for this rule it in any manner. @spence-s

@spence-s
Copy link
Contributor

spence-s commented May 30, 2024

This issues is definitely not closed. This is not a fix for the problem, that it is not possible to provide the correct configuration for this rule it in any manner.

Your example is syntactically wrong. The error you pasted explicitly tells you that it is incorrect syntax and that you are missing the severity.

See my example below, it works just fine. - also the original issue was not about this rule, but about xo not finding @typescript-eslint rules which I gave a valid work around for...

This works totally fine for me - using the latest xo

module.exports = {
	prettier: true,
	parserOptions: {
		project: './tsconfig.xo.json',
	},
	rules: {
		'@typescript-eslint/naming-convention': ['error',{
                      selector: 'variable',
                      types: ['boolean'],
                      format: ['PascalCase'],
                      prefix: ['is', 'should', 'has', 'can', 'did', 'will'],
                  }],
             ],
	}
};

(actual file not shown, just the line that uses the rule)

const Test = true;
  src/server.ts:28:7
  ✖  28:7  Variable name Test must have one of the following prefixes: is, should, has, can, did, will  @typescript-eslint/naming-convention
  ✖  28:7  Test is assigned a value but never used.                                                     @typescript-eslint/no-unused-vars

@simwai
Copy link

simwai commented May 30, 2024

Thanks for your reply, will try that out. Ok, my issues is solved too then. Thanks for your time. :)

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

No branches or pull requests

3 participants