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

Bug: [naming-convention] Default import config clashes with common npm import patterns (PascalCase and other-cased imports) #7838

Closed
4 tasks done
karlhorky opened this issue Oct 25, 2023 · 2 comments · Fixed by #7841
Assignees
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@karlhorky
Copy link

karlhorky commented Oct 25, 2023

Originally reported over here + confirmed by @JoshuaKGoldberg :

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.2.2&fileType=.tsx&code=JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6JgQwFtmBzWsgHsmAN0QtKw9GADa4bDkTRog6JAA08hVgXZIyREjL5V0yABNEAMw4J8GrbshXVXDvYxzdTst0MBhDgNIRwUAXU1vHCQOcz4AVSZLaGQhaEQzDnh4QQB3ByiofGgOSkYmXkTk1NUMjEgsnPzQsABfSN0db31DRGNTepEOKg4AIyQCqOdXd2kvQqhfLgCgjI7CyHiABS2AUQAlAH1-AEEAZV2QwoiW6MRYhKSlGvTM7LzJ7uLS8sqnlLSdSgjQ%2BLXaLS6TgMRhManqRFIABlKABrNa3KAuaBuDyyDE4LZBXzwQLBDFhMGOCkQVogVpAA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Screenshot 2023-10-25 at 15 11 52

Repro Code

import React from 'react';

ESLint Config

This is using [the default rule configuration mentioned in the docs](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/naming-convention.md#options):


// the default config is similar to ESLint's camelcase rule but more strict
const defaultOptions: Options = [
  {
    selector: 'default',
    format: ['camelCase'],
    leadingUnderscore: 'allow',
    trailingUnderscore: 'allow',
  },

  {
    selector: 'variable',
    format: ['camelCase', 'UPPER_CASE'],
    leadingUnderscore: 'allow',
    trailingUnderscore: 'allow',
  },

  {
    selector: 'typeLike',
    format: ['PascalCase'],
  },
];


module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/naming-convention": ["error", ...defaultOptions],
  },
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

Just upgraded to @​typescript-eslint/eslint-plugin@6.9.0 with the new import option for naming-convention config and received a number of new warnings, such as this one:

checkbox/index.js
Warning:   1:8  warning  Import name `React` must match one of the following formats: camelCase  @typescript-eslint/naming-convention

With this code:

import React from 'react';

I guess this is going to be a pretty common pattern that gets rejected now. 😬

Actual Result

Maybe the default configuration should accept every format as an import? (format: null)

Alternative: expect all users with default PascalCase imports (pretty common across the npm ecosystem, incl. React) and other case format eg. UPPER_CASE or snake_case to add the following to their config:

// the default config is similar to ESLint's camelcase rule but more strict
const defaultOptions: Options = [
  // ...

+  // Disable @typescript-eslint/naming-convention format for imports
+  // https://github.com/typescript-eslint/typescript-eslint/pull/7269#issuecomment-1777628591
+  {
+    selector: 'import',
+    format: null,
+  },
];

Additional Info

No response

@karlhorky karlhorky added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Oct 25, 2023
@karlhorky karlhorky changed the title Bug: [naming-convention] Default import format Bug: [naming-convention] Default import config clashes with common npm ecosystem pattern (PascalCase and other-cased imports) Oct 25, 2023
@karlhorky karlhorky changed the title Bug: [naming-convention] Default import config clashes with common npm ecosystem pattern (PascalCase and other-cased imports) Bug: [naming-convention] Default import config clashes with common npm import patterns (PascalCase and other-cased imports) Oct 25, 2023
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for maintainers to take a look labels Oct 25, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Oct 26, 2023
@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Oct 26, 2023

Thanks for (re-)filing! I'll take this on, I should have caught that this would happen in PR review.

@karlhorky
Copy link
Author

Glad to help :) Thanks for the quick turnaround!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants