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: [@typescript-eslint/keyword-spacing] Unexpected space(s) before "{" in import type #6063

Closed
4 tasks done
crystalfp opened this issue Nov 22, 2022 · 3 comments · Fixed by #6095
Closed
4 tasks done
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@crystalfp
Copy link

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

none

Repro Code

import type {SavedQueries} from "./SavedQueries.js";
import type http2 from "node:http2";
import type http from "node:http";

where SavedQueries.js contains only: export const SavedQueries;

ESLint Config

parser: '@typescript-eslint/parser'

plugins:
    - '@typescript-eslint'

extends:
    - 'eslint:recommended'
    - 'plugin:@typescript-eslint/recommended'
    - 'plugin:@typescript-eslint/recommended-requiring-type-checking'

parserOptions:
    ecmaVersion: 2021
    ecmaFeatures:
        impliedStrict: true
    project:
        - ./server/tsconfig.json

settings:
    import/parsers: {'@typescript-eslint/parser': [.ts, .tsx]}
    import/resolver: {typescript: {}}
    import/extensions: [.js, .ts]
    import/ignore: [node_modules]

env:
    es2021: true
    node: true

rules:
    keyword-spacing: off
    '@typescript-eslint/keyword-spacing':
        - warn
        - before: true
          after: false
          overrides:
            else: {after: true}
            return: {after: true}
            try: {after: true}
            catch: {after: false}
            case: {after: true}
            const: {after: true}
            throw: {after: true}
            let: {after: true}
            do: {after: true}
            of: {after: true}
            as: {after: true}
            finally: {after: true}
            from: {after: true}
            import: {after: true}
            export: {after: true}
            default: {after: true}

tsconfig

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
        "esnext",
    ],
    "removeComments": true,
    "strict": true,
    "alwaysStrict": true,
    "useDefineForClassFields": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "moduleResolution": "node",
    "types": [
        "node",
    ],
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "resolveJsonModule": true,
    "forceConsistentCasingInFileNames": true,
    "importsNotUsedAsValues": "remove",
    "strictNullChecks": true
  },
  "include": [
      "*"
  ],
  "exclude": [
      "./node_modules",
      "./tests"
  ]
}

Expected Result

The rule always worked on my codebase with version 5.43.0. The error message appeared as soon as I moved to version 5.44.0

Actual Result

warning: Unexpected space(s) before "{" (@typescript-eslint/keyword-spacing) at server\ServerResources.ts:13:13:
> 13 | import type {SavedQueries} from "./SavedQueries.js";
     |             ^
  14 | import type http2 from "node:http2";
  15 | import type http from "node:http";
  16 |

warning: Unexpected space(s) before "http2" (@typescript-eslint/keyword-spacing) at server\ServerResources.ts:14:13:
  13 | import type {SavedQueries} from "./SavedQueries.js";
> 14 | import type http2 from "node:http2";
     |             ^
  15 | import type http from "node:http";
  16 |

warning: Unexpected space(s) before "http" (@typescript-eslint/keyword-spacing) at server\ServerResources.ts:15:13:
  13 | import type {SavedQueries} from "./SavedQueries.js";
  14 | import type http2 from "node:http2";
> 15 | import type http from "node:http";
     |             ^
  16 |

Additional Info

Also it is not possible to add as overrides the line type: {after: true} that elicits the following error running eslint:

Oops! Something went wrong! :(

ESLint: 8.28.0

Error: --config:
        Configuration for rule "@typescript-eslint/keyword-spacing" is invalid:
        Value {"else":{"after":true},"return":{"after":true},"try":{"after":true},
"catch":{"after":false},"case":{"after":true},"const":{"after":true},"throw":{"after":true},
"let":{"after":true},"do":{"after":true},"of":{"after":true},"as":{"after":true},"finally":{"after":true},
"from":{"after":true},"import":{"after":true},"export":{"after":true},"default":{"after":true},
"type":{"after":true}} should NOT have additional properties.

Versions

package version
@typescript-eslint/eslint-plugin 5.44.0
@typescript-eslint/parser 5.44.0
TypeScript 4.9.3
ESLint 8.28.0
node 18.12.1
@crystalfp crystalfp 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 Nov 22, 2022
@bradzacher

This comment was marked as outdated.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party please fill out the template we have the processes for good reasons 😔 and removed triage Waiting for maintainers to take a look labels Nov 23, 2022
@nmss
Copy link

nmss commented Nov 24, 2022

@bradzacher here you can find a playground that shows the issue playground

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. and removed awaiting response Issues waiting for a reply from the OP or another party please fill out the template we have the processes for good reasons 😔 labels Nov 24, 2022
@typescript-eslint typescript-eslint deleted a comment from blephy Nov 28, 2022
@jdforsythe
Copy link

jdforsythe commented Nov 30, 2022

We have what I believe to be the same issue. The addition of type in #5977 broke the default behavior. Our rule was simply:

"@typescript-eslint/keyword-spacing": ["error"] so it would use the default { "before": true, "after": true }. After this PR, the following code errors:

import type * as Bull from 'bull';

or

import type { Job } from 'bull';

however this does not error:

import { type Job } from 'bull';

We would expect all of these to pass, as the default is to require spaces before and after, but typescript-eslint wants to remove the space before the * and before the { when type is outside the curlies.

This is a bug because it broke the default behavior. If we set the options to: ["error", {"before": true, "after": true}], which should be the default according to the docs and previous behavior, it fixes the errors - so the new type rule is apparently not respecting unset defaults for before/after.

There should probably also be an override for type to allow configuring it as one would desire, which would only apply when the type keyword is outside the curlies or is followed by a *.

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 formatting Related to whitespace/bracket formatting. We strongly recommend you use a formatter instead. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
5 participants