Skip to content

Bug: [@typescript-eslint/keyword-spacing] Unexpected space(s) before "{" in import type #6063

Closed
@crystalfp

Description

@crystalfp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingformattingRelated to whitespace/bracket formatting. We strongly recommend you use a formatter instead.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions