daidodo / format-imports-vscode

Format imports and exports for JavaScript and TypeScript in VS Code.
https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter
MIT License
62 stars 5 forks source link

Flag to disable ESLint checking #47

Closed daidodo closed 3 years ago

daidodo commented 3 years ago

Moving a new feature request to this new issue:

Is there any interest in adding a flag to disable ESLint checking? We currently use (and love) this tool but the 7.3.0 update broke our setup because the ESLInt config takes precedence over our import-sorter.json.

We use a max-len for our code, but not imports.

Our ESLint has a max length of 100, but for the import sorter it's 0 (no max at all).

We don't need nicely formatted imports, so we allow unlimited line length just for the imports.

When eslint max-len is set, it breaks that usage pattern since it "overrides" the import-sorter.json.

Thanks for taking the time to check it out!

.eslintrc

{
"env": {
"es6": true,
"react-native/react-native": true
},
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
}
},
"plugins": [
"@typescript-eslint",
"jest",
"react",
"react-native",
"react-hooks"
],
"ignorePatterns": [
"node_modules",
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended"
],
"rules": {
"max-len": ["warn", {
"code": 100,
"tabWidth": 2,
"ignoreComments": true,
"ignoreStrings": true,
"ignoreTrailingComments": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true,
}],
}

import-sorter.json

{
  "autoFormat": "onSave",
  "formatExports": false,
  "exclude": ["scripts/", "node_modules"],
  "sortImportsBy": "paths",
  "maxLineLength": 0,
  "bracketSpacing": true,
  "wrappingStyle": {
    "maxBindingNamesPerLine": 0,
    "maxNamesPerWrappedLine": 0,
    "maxDefaultAndBindingNamesPerLine": 0,
    "maxExportNamesPerLine": 0
  },
  "emptyLinesAfterAllImports": 2,
  "groupRules": [
    {
      "regex": "^react(-native)?$"
    },
    {},
    {
      "subGroups": [
        "^@(src|assets|components|constants|context|helpers|hooks|navigation|screens|types|graphql)",
        "^@DATA$",
        "^[.]+",
        "^[.]"
      ]
    }
  ]
}
dburdan commented 3 years ago

I should've created a new issue in the first place. Thanks again for taking the time to look into this.

daidodo commented 3 years ago

May I ask why you disable formatExports and what if exports exceed 100 line length?

dburdan commented 3 years ago

Just disabled for now as we get formatting implemented each step at a time.

We won't format exports either and will have them at unlimited line length.

daidodo commented 3 years ago

Thanks! Before getting into the solution, I'd like to clarify some options in your import-sorter.json:

dburdan commented 3 years ago

Thanks for the heads up. Even though those are default, I feel it's nice to explicitly list some properties in case the defaults were to change in a future version.

daidodo commented 3 years ago

Yes, it's up to you.

Regarding the new feature, my understanding is you want the plugin to ignore max-len rule because you've disabled it for imports and exports.

And I also noticed that your import-sorter.json has "emptyLinesAfterAllImports": 2 which can be replaced by ESLint rule import/newline-after-import if you want.

And that brings me to another use case that people might want some rules being ignored while others are in effect.

So my suggestion is as follows:

Some notes:

@dburdan, please tell me your thoughts. Thanks!

dburdan commented 3 years ago

Thanks for the tip on the emptyLinesAfterAllImports ESLint rule, we'll definitely use that!

I think your solution above would work perfectly, and also allow room for new use-cases other teams may encounter. That would solve our problems 👍🏼

daidodo commented 3 years ago

@dburdan - Sorry for the late response as I was busy recently! But now the feature is out in v7.4.0! Please check it out and tell me if you have any questions.

Thanks!

dburdan commented 3 years ago

Amazing, thanks so much! I'll give it a try as soon as the update is available.

dburdan commented 3 years ago

Upgraded and working 👍🏼 I think it's safe to say this issue can be closed.