Skip to content

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

Closed

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 }],
    },
  },
]);

Activity

  1. emmnull commented on Dec 20, 2024

    @emmnull
    Author

    Nevermind, just realized there was a considerComments option (questionably) defaulting to false.

  2. ljharb commented on Dec 20, 2024

    @ljharb
    Member

    It's not questionable at all; it would have been a breaking change to default that behavior to true.

  3. emmnull commented on Dec 20, 2024

    @emmnull
    Author

    Ah, yeah my wording might've come off a bit harsh, didn't mean to! Genuinely curious though now that you mention it, what specific to comments but not code would've made this a breaking change?

  4. ljharb commented on Dec 20, 2024

    @ljharb
    Member

    It could have created warnings or diffs on codebases that had no warnings or autofix diffs previously.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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