eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

[newline-after-import] Ignore comments between imports

Open regseb opened this issue 2 years ago • 1 comments

Ignore comments between imports when option considerComments is actived in import/newline-after-import.

  • index.js

    import foo from "foo";
    // Bar.
    // Baz.
    import qux from "qux";
    
    // Quux.
    
  • package.json

    {
        "name": "testcase",
        "version": "1.0.0",
        "type": "module",
        "devDependencies": {
            "eslint": "9.12.0",
            "eslint-plugin-import": "2.31.0"
        }
    }
    
  • eslint.config.js

    import pluginImport from "eslint-plugin-import";
    
    export default [{
        plugins: { "import": pluginImport },
    
        rules: {
            "import/newline-after-import": ["error", { considerComments: true }]
        }
    }];
    
  1. npm install

  2. npx eslint

    /home/regseb/testcase/index.js
      1:1  error  Expected 1 empty line after import statement not followed by another import  import/newline-after-import
    
    ✖ 1 problem (1 error, 0 warnings)
      1 error and 0 warnings potentially fixable with the `--fix` option.
    

regseb avatar Jan 13 '23 18:01 regseb

I'd like to +1 this. I have an issue where I have a eslint-disable directive in the middle of my imports, and newline-after-import is incorrectly determining this to be the end of my import statements and therefore I need to have a space before it, which I do not want.

christopher-buss avatar Jan 07 '24 11:01 christopher-buss