Skip to content

'newline-after-import' not applied to jsdoc #3125

@emmnull

Description

@emmnull

The newline-after-import rule does not appear to work when the first content encountered after imports is JSDoc. Take the following eslint.config.js as an example:

import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginImport from 'eslint-plugin-import';
import globals from 'globals';
import ts from 'typescript-eslint';
/**
 * @type {import('eslint').Linter.Config[]}
 */
export default ts.config([
  eslintConfigPrettier,
  js.configs.recommended,
  ...ts.configs.strict,
  ...ts.configs.stylistic,
  {
    plugins: {
      import: eslintPluginImport,
    },
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.browser,
      },
    },
    rules: {
      'import/newline-after-import': ['error', { count: 1 }],
    },
  },
]);

ESLint doesn't indicate the expected error after the import statements, but removing the JSDoc will result in the correct behavior:

import js from '@eslint/js';
import eslintConfigPrettier from 'eslint-config-prettier';
import eslintPluginImport from 'eslint-plugin-import';
import globals from 'globals';
import ts from 'typescript-eslint'; // Expected 1 empty line after import statement not followed by another import.eslint[import/newline-after-import](https://github.com/import-js/eslint-plugin-import/blob/v2.31.0/docs/rules/newline-after-import.md)
export default ts.config([
  eslintConfigPrettier,
  js.configs.recommended,
  ...ts.configs.strict,
  ...ts.configs.stylistic,
  {
    plugins: {
      import: eslintPluginImport,
    },
    languageOptions: {
      globals: {
        ...globals.node,
        ...globals.browser,
      },
    },
    rules: {
      'import/newline-after-import': ['error', { count: 1 }],
    },
  },
]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions