import-js/eslint-plugin-import

[newline-after-import] Ignore comments between imports

Open

#2673 aperta il 13 gen 2023

Vedi su GitHub
 (1 commento) (3 reazioni) (0 assegnatari)JavaScript (1540 fork)batch import
help wanted

Metriche repository

Star
 (4946 star)
Metriche merge PR
 (Merge medio 138g 22h) (3 PR mergiate in 30 g)

Descrizione

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.
    

Guida contributor