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

Plugin doesn't check for typescript rules #226

Closed
zeromask1337 opened this issue Nov 4, 2024 · 5 comments · Fixed by #231
Closed

Plugin doesn't check for typescript rules #226

zeromask1337 opened this issue Nov 4, 2024 · 5 comments · Fixed by #231

Comments

@zeromask1337
Copy link

My eslint config has typescript rule

'@typescript-eslint/no-unused-vars': ['error', {
  caughtErrors: 'none',
}],

eslint-plugin-oxlint is configured in eslint.config

  },
  ...buildFromOxlintConfigFile('./.oxlintrc.json'),
)

When I run npx oxlint -c .oxlintrc.json || npx eslint unused var rule appear both in oxlint and eslint log. Same file, same line.

oxlint log

 × typescript-eslint(no-explicit-any): Unexpected any. Specify a different type.
   ╭─[src/shared/lib/capitalizeFirstLetter.ts:2:44]
 1 │ /** @description Foobar*/
 2 │ export const capitalizeFirstLetter = (str: any) => {
   ·                                            ───
 3 │   return str.trim().charAt(0).toUpperCase() + str.trim().slice(1)
   ╰────

eslint log

/path/to/my/project/src/shared/lib/capitalizeFirstLetter.ts
  2:44  error  Unexpected any. Specify a different type  @typescript-eslint/no-explicit-any
@Sysix
Copy link
Collaborator

Sysix commented Nov 4, 2024

Hello,

you are writing about @typescript-eslint/no-unused-vars but your logs outputting @typescript-eslint/no-explicit-any.
Can you show me more about the .oxlintrc.json, I need to know what categories and plugins you defined and if the rule is specificly enabled in your .oxlintrc.json.

@zeromask1337
Copy link
Author

My bad, issue was originally about no-explicit-any

Oxlint config

{
  "$schema": "./node_modules/oxlint/configuration_schema.json",
//  "categories": {
//    "correctness": "off",
//    "nursery": "off",
//    "pedantic": "off",
//    "perf": "off",
//    "restriction": "off",
//    "style": "off",
//    "suspicious": "off"
//  },
  "rules": {
    "no-unused-vars": "error",
    "no-console": "off",
    "no-explicit-any": "error",
    "prefer-as-const": "error",
    "no-dynamic-delete": "error",
    "no-var-requires": "error"
  }
}

eslint config

// @ts-check
import { buildFromOxlintConfigFile } from 'eslint-plugin-oxlint'
import withNuxt from './.nuxt/eslint.config.mjs'

export default withNuxt(
  {
    files: ['**/*.ts', '**/*.vue'],
    rules: {
      'no-console': 'off',
      '@stylistic/brace-style': ['error', '1tbs', { allowSingleLine: true }],
      '@typescript-eslint/no-unused-vars': ['error', {
        caughtErrors: 'none',
      }],
      '@typescript-eslint/no-extraneous-class': 'off',
      'vue/max-attributes-per-line': [
        'error',
        {
          singleline: {
            max: 2,
          },
          multiline: {
            max: 1,
          },
        },
      ],

      'vue/component-name-in-template-casing': [
        'error',
        'PascalCase',
        {
          // registeredComponentsOnly: false,
          ignores: ['nuxt-link'],
        },
      ],

      'vue/attributes-order': [
        'error',
        {
          order: [
            // 'is', 'v-is'
            'DEFINITION',
            // 'v-for'
            'LIST_RENDERING',
            // 'v-if', 'v-else-if', 'v-else', 'v-show', 'v-cloak'
            'CONDITIONALS',
            // 'v-once', 'v-pre'
            'RENDER_MODIFIERS',
            // 'id'
            'GLOBAL',
            // 'ref', 'key' |  'v-slot', 'slot'
            ['UNIQUE', 'SLOT'],
            // 'v-model'
            'TWO_WAY_BINDING',
            // 'v-custom-directive'
            'OTHER_DIRECTIVES',
            // 'boolean-prop'
            'ATTR_SHORTHAND_BOOL',
            // 'prop="foo"', 'custom-prop="foo"'
            'ATTR_STATIC',
            // 'v-bind:prop="foo"', ':prop="foo"'
            'ATTR_DYNAMIC',
            // '@click="functionCall"', 'v-on="event"'
            'EVENTS',
            // 'v-text', 'v-html'
            'CONTENT',
          ],
          alphabetical: true,
        },
      ],

      'vue/html-self-closing': [
        'error',
        {
          html: {
            void: 'any',
            normal: 'always',
            component: 'always',
          },
          svg: 'always',
          math: 'always',
        },
      ],

      'import/named': 'off',

      'vue/html-indent': [
        'error',
        2,
        {
          attribute: 1,
          baseIndent: 1,
          closeBracket: 0,
          alignAttributesVertically: true,
          ignores: [],
        },
      ],

      'vue/component-definition-name-casing': ['error', 'PascalCase'],

      'vue/match-component-file-name': [
        'warn',
        {
          extensions: ['vue'],
          shouldMatchCase: false,
        },
      ],

      'vue/order-in-components': [
        'error',
        {
          order: [
            'el',
            'name',
            'key',
            'parent',
            'functional',
            ['delimiters', 'comments'],
            ['components', 'directives', 'filters'],
            'extends',
            'mixins',
            ['provide', 'inject'],
            'ROUTER_GUARDS',
            'layout',
            'middleware',
            'validate',
            'scrollToTop',
            'transition',
            'loading',
            'inheritAttrs',
            'model',
            ['props', 'propsData'],
            'emits',
            'setup',
            'asyncData',
            'data',
            'fetch',
            'head',
            'computed',
            'watch',
            'watchQuery',
            'LIFECYCLE_HOOKS',
            'methods',
            ['template', 'render'],
            'renderError',
          ],
        },
      ],

      'no-void': ['error', { allowAsStatement: true }],
      '@typescript-eslint/no-explicit-any': 'error',
      '@typescript-eslint/no-unused-expressions': ['error', { allowShortCircuit: true }],
    },
  },
  ...buildFromOxlintConfigFile('./.oxlintrc.json'),
)

@Sysix
Copy link
Collaborator

Sysix commented Nov 4, 2024

buildFromOxlintConfigFile expects that only @typescript-eslint/no-explicit-any works for oxlint.
Currently the following are allowed:

  • no-explicit-any
  • typescript/no-explicit-any
  • @typescript-eslint/no-explicit-any

@DonIsaac is this expected and is the same for other plugins too?

@drvn-mr
Copy link

drvn-mr commented Nov 5, 2024

Some of the typescript-extended rules are inherently supported by oxlint and thus are only advertised as a single rule.
It's a bit annoying having to match rules when they are different names.

@Sysix
Copy link
Collaborator

Sysix commented Nov 5, 2024

@drvn-mr moved your issue to a own ticket.

This issue is about the different supported names in oxlint.
~~After reading the source code I don't think no-explicit-any should do anything. There is no eslint version of it but let me double check it with another person :) ~~

EDIT: this is expected in oxlint and a bug in this library. thanks for reporting

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

Successfully merging a pull request may close this issue.

3 participants