sublimelsp / LSP-eslint

ESLint support for Sublime LSP plugin
MIT License
36 stars 5 forks source link

LSP-eslint Workspace settings overrides not working #66

Closed davidwebca closed 9 months ago

davidwebca commented 9 months ago

Hi.

I am trying to set my subfolder's config file (nuxt/.eslintrc.js) and my nuxt subdirectory as the root when my Sublime project is set one level higher.

/
/project.sublime-project
/nuxt
/nuxt/.eslintrc.cjs

My sublime project file contains this :

{
  "folders":
  [
    {
      "path": "."
    }
  ],
  "settings": {
    "LSP": {
      "LSP-eslint": {
        "settings": {
          "workingDirectories": [
            {
              "!cwd": true,
              "directory": "./nuxt"
            }
          ]
        }
      }
    }
  }
}

The eslint config seems to be loaded with my rules, but the aliases aren't working because LSP-eslint considers itself working from the root directory. For example, import whatever from "~/something/wow.js" reports an error, but import whatever from "~/nuxt/something/wow.js" removes the error. Another trick I'm doing right now is to open a new sublime window in nuxt subdirectory directly and everything works file, so LSP-eslint seems to really need to work at the root directory only and seems to ignore settings that tell it otherwise.

Here's my .eslintrc.cjs config file in case it contains something that could give a clue.

const twConfig = require('./tailwind.config.cjs');

module.exports = {
    root: true,
    env: {
        browser: true,
        es2021: true,
        node: true,
    },
    extends: ['airbnb-base', 'plugin:vue/vue3-recommended', 'plugin:tailwindcss/recommended'],
    parserOptions: {
        ecmaVersion: 2022,
    },
    plugins: ['vue', 'tailwindcss'],
    rules: {
        indent: ['error', 4],
        'import/extensions': 'off',
        'import/no-extraneous-dependencies': [0, { 'packageDir ': './' }],
        'max-len': [
            'error',
            {
                code: 160,
                ignorePattern: 'class="([\\s\\S]*?)"|d="([\\s\\S]*?)"', // ignore classes or svg draw attributes
                ignoreUrls: true,
            },
        ],
        'vue/multi-word-component-names': 'off',
        'vue/script-indent': [
            'error',
            4,
            {
                baseIndent: 0,
                switchCase: 0,
            },
        ],
        'vue/html-indent': [
            'error',
            4,
            {
                attribute: 1,
                baseIndent: 1,
                closeBracket: 0,
                alignAttributesVertically: true,
            },
        ],
        'vue/max-attributes-per-line': [
            'error',
            {
                singleline: {
                    max: 2,
                },
                multiline: {
                    max: 1,
                },
            },
        ],
        'vue/v-on-style': ['error', 'longform'],
        'tailwindcss/no-custom-classname': [0],
        'tailwindcss/classnames-order': [1, { config: twConfig }],
        'no-plusplus': 0,
        'vue/no-v-html': 0,
        'no-unused-vars': 'warn',
        'no-debugger': 'warn',
        'no-console': 'warn',
        'no-underscore-dangle': 0,
        'no-undef': 0,
        'import/prefer-default-export': 'off',
    },
    settings: {
        'import/resolver': {
            node: {
                extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.svg', '.css'],
                moduleDirectory: ['node_modules', './'],
            },
            alias: {
                extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue', '.svg', '.css'],
                map: [['~', './']],
            },
            typescript: {},
        },
    },
    overrides: [
        {
            files: ['*.vue'],
            parser: 'vue-eslint-parser',
            rules: {
                indent: 'off',
            },
        },
    ],
};
predragnikolic commented 9 months ago

. For example, import whatever from "\~/something/wow.js" reports an error, but import whatever from "\~/nuxt/something/wow.js" removes the error

Can you provide a screenshot of the exact error that you are seeing? A repository that can reproduce the problem you are experiencing would definitely help.

I tried to setup a project with the info you provided, but I do not see any errors at the import statement. (I assume that I didn't setup the project as you did)

davidwebca commented 9 months ago

Here you go.

https://github.com/davidwebca/lsp-eslint-issue-66-repro

With the settings activated in the repro.sublime-project file, I have no error reported for the aliases (good), but all my rules and autofix on save doesn't work (bad).

If I remove the settings in the repro.sublime-project file, I have errors on aliases (bad), but autofix and rules work properly.

The aliases + working in a subfolder is really the combo that seems to fail.

rchl commented 9 months ago

which file shows the issue?

rchl commented 9 months ago

Why are you using !cwd option? This instructs eslint server to not change the working directory while you want the opposite. Try with just "workingDirectories": ["./nuxt"].

Also refer to the documentation: https://github.com/microsoft/vscode-eslint#settings-options

davidwebca commented 9 months ago

🤦 You're absolutely right. I was sure I had tested it with and without, but now it works if I remove the !cwd. I had understood the reverse, I thought it was a way to force the current working directory. Closing, everything's fine now! Sorry for wasting your time.