0

How to enable eslint in Laravel vendor folder?

The main development takes place within vendor folder. Our project based on Laravel packages. I have enabled and configure eslint in the "root" project and it works fine. Currently work in PHPStorm and use eslint in it.

.eslintrc.json

{
    "env": {
        "es6": true,
        "node": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:vue/essential",
        "plugin:prettier/recommended"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "vue",
        "prettier"
    ],
    "rules": {
        "no-unused-vars": "warn"
    }
}

.prettierrc.json

{
    "trailingComma": "es5",
    "tabWidth": 4,
    "semi": false,
    "singleQuote": true
}

resources/js/components/App.vue - Fix ESlint Problems:

resources/js/components/App.vue - Fix ESlint Problems

But in vendor package it doesn't.

vendor\testpackage\uitest01\recources\js\components\TestTwoComponent.vue - Fix ESlint Problems isn't presented:

vendor\testpackage\uitest01\recources\js\components\TestTwoComponent.vue - Fix ESlint Problems isn't presented

Any ideas how enable it? Thank you!

5
  • Would be interesting to see your config file. Commented Jan 22, 2020 at 10:23
  • @Aer0 It's very basic: { "env": { "es6": true, "node": true }, "extends": [ "eslint:recommended", "plugin:vue/essential", "plugin:prettier/recommended" ], "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly" }, "parserOptions": { "ecmaVersion": 2018, "sourceType": "module" }, "plugins": [ "vue", "prettier" ], "rules": { "no-unused-vars": "warn" } } Plus prettier: "trailingComma": "es5", "tabWidth": 4... Commented Jan 22, 2020 at 10:28
  • 1
    Would you mind putting that into your question please? That's the place where it belongs to. Also it's easier to read there. Commented Jan 22, 2020 at 10:31
  • Are you sure the directory isn't being ignore anywhere like in .eslintignore or .gitignore? It should be. It's really not a good idea to modify files in the vendor directory. It will be overwritten any time you want to upgrade your dependencies. Rather fork the packages you want to modify. Commented Jan 22, 2020 at 10:57
  • 1
    @DelenaMalan I have no .eslintignore but I have .gitignore... I'm not sure that is connected with eslint. But it's good idea (generally), to do somthng with .gitignore in this case :) I'm working on my own package. Thank you ) Commented Jan 22, 2020 at 11:14

1 Answer 1

2

In Laravel projects, vendor packages are auto-added to PHP Include paths and thus are treated as libraries. But inspections are not enabled in library files, and linter errors are not reported for them. Try removing your package from Include Path list in Settings | Languages & Frameworks | PHP:

enter image description here

and then un-exclude the vendor/testpackage/uitest01 folder. This should help:

enter image description here

Remove packages as libraries permanently:

In Settings | Languages & Frameworks | PHP | Composer, try disabling Add packages as libraries to avoid auto-adding packages to Include path (you will then need to add the packages you'd like being treated as libraries manually)

Sign up to request clarification or add additional context in comments.

3 Comments

Almost there :) Unfortunately after restart of PHPStorm, the setting is resetting :( ...and ESlinter still doesn't work, only prettier. I tried to make /.idea/php.xml file read only, it works with small error: Could not save project: Unable to save project files. Please ensure project files are writable and you have permissions to modify them. Try to save project again.
in Settings | Languages & Frameworks | PHP | Composer, try disabling Add packages as libraries to avoid auto-adding packages to Include path (you will then need to add the packages you'd like being treated as libraries manually)
Great! Thank you! This is what I need :) I'm using PHPStorm as big nice code editor, and doing all composer things from external cli. I don't care if IDE know nothing about composer and libraries :) And ESlint now works, good!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.