Open sharh opened 7 months ago
Here is the ESLint
config file .eslintrc.js
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
// npm install --save-dev @typescript-eslint/eslint-plugin
"plugin:@typescript-eslint/recommended",
// npm install --save-dev eslint-config-prettier
"prettier",
// npm install --save-dev eslint-plugin-react
"plugin:react/jsx-runtime",
// npm install --save-dev @next/eslint-plugin-next
"plugin:@next/next/recommended",
// npm install --save-dev eslint-plugin-react-hooks
"plugin:react-hooks/recommended",
// npm install eslint-plugin-import --save-dev
"plugin:import/recommended",
// 支持ts
"plugin:import/typescript",
// npm install eslint-plugin-yml --save-dev
"plugin:yml/recommended",
],
globals: {
wx: "readonly",
},
settings: {
react: {
version: "detect",
},
next: {
rootDir: ".",
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx", ".mdx"],
},
"import/resolver": {
typescript: true,
node: true,
},
},
// npm install --save-dev @typescript-eslint/parser
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
ignorePatterns: [
"megalinter-reports/**/*",
"!.lintstagedrc.cjs",
"!.stylelintrc.cjs",
"!.commitlintrc.cjs",
"!.eslintrc.js",
],
overrides: [
{
files: [".eslintrc.{js,cjs}", "**/*.tsx", "**/*.cjs", "**/*.ts", "**/*.mjs", "**/*.jsx", "**/*.mdx"],
rules: {
quotes: "off",
"@typescript-eslint/no-explicit-any": "warn",
"import/first": 2,
},
},
{
files: ["*.yaml", "*.yml"],
parser: "yaml-eslint-parser",
// Options used with yaml-eslint-parser.
parserOptions: {
defaultYAMLVersion: "1.2",
},
},
],
noInlineConfig: true,
};
@sharh as eslint is installed globally, I think you don't have other choice than installing plugins using the full command in PRE_COMMANDS, like npm install @next/eslint-plugin-next
But you remark is very valid... we could add an option to parse package.json and automatically build & run the dependencies commands to install :)
Thanks for repy.If that becomes true, that would be very nice. And when will it be true?
@sharh when someone makes a Pull Request to make it available :) Maybe you ? ^^ I my side I already have a big backlog ^^
I imagine some config like JAVASCRIPT_ESLINT_USE_NPM=true
, and if found, it would run npm install
then call eslint via npm run eslint
:)
Wouldn't it make it really hard to support, on our side? Npm is pretty intertwined. Unless there is a kind of environment possible.
@echoix in that case would run the eslint installed by npm install and not the one contained in MegaLinter image... it would be something experimental and disabled by default, as like you i'm not 100% sure it wouldn't generate regressions
I was more thinking on the side that we can't officially offer support for something that we can't control. It's not really testable on our side, and their setup would have to work with what node versions we ship. Does the install of node_modules would like "uninstall" our linters (or downgrade them) to satisfy dependencies? Does an "virtualenv" concept exist in node? What happens if we change the way we package/install our linters? As always, precommands can be used to do anything users want..
@echoix our node_modules are installed in /node-deps , i assume what I propose would install them in working directory/node_modules, so it wouldn't mess with our installs ^^ But maybe I missed something ? :/
So basicaly I have similar problem. I'm trying to use TYPESCRIPT_ES with my dependencies to install in
PRE_COMMANDS:
- command: npm install @angular-eslint/eslint-plugin --save-dev -g
cwd: "root"
output is like this:
[Pre] run: [cd /node-deps && npm install @angular-eslint/eslint-plugin --save-dev -g] in cwd [/]
[Pre] result:
added 136 packages in 3s
31 packages are looking for funding
run `npm fund` for details
But later I get:
- Using [eslint v8.54.0] https://megalinter.io/7.6.0/descriptors/typescript_eslint
- MegaLinter key: [TYPESCRIPT_ES]
- Rules config: [/.eslintrc.json]
- Number of files analyzed: [797]
--Error detail:
Oops! Something went wrong! :(
ESLint: 8.54.0
ESLint couldn't find the plugin "@angular-eslint/eslint-plugin".
(The package "@angular-eslint/eslint-plugin" was not found when loaded as a Node module from the directory "/tmp/lint".)
It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:
npm install @angular-eslint/eslint-plugin@latest --save-dev
The plugin "@angular-eslint/eslint-plugin" was referenced from the config file in "--config#overrides[0]".
I've tried in PRE_COMMANDS also cwd: workspace
but with te same results.
Where I should install npm package to make it discoverable and work?
EDIT: for future reference, I managed to make it work with command: npm install --production=false
Regarding prettier plugins: They can only be discovered by MegaLinter's prettier if you point to the exact location in .prettierrc.js
using require.resolve
:
module.exports = {
plugins: ['prettier-plugin-svelte'], // does not work
}
module.exports = {
plugins: [require.resolve('prettier-plugin-svelte')], // works
}
Afterward, plugins can be installed using PRE_COMMANDS
, as usual:
PRE_COMMANDS:
- command: npm install prettier-plugin-svelte
This might be relevant, if MegaLinter tries to install the required plugins based on the package.json
or for anyone using prettier plugins in the meantime.
Describe the bug when use eslint, need to install the dependencies first, because in the soure code, some lib needs: in nextjs
layout.tsx
when run
eslint
, it needs not just eslint plugins, but also lib deps. Thus I need to install the full deps in package.jsonTo Reproduce Here is the
.mega-linter.yml
As you can see, here is the
PRE_COMMANDS
It's failed: here is the
package.json
file in projectAll the deps are declared and worked well in local. Expected behavior
After
npm install
the linter can work well when use eslintAdditional context When i use the sample config to install single plugin, it works.
It seems that
ESLINT
works inroot
, not work well inworkspace
.How ever, there is a lot of deps in
package.json
, if all list inPRE_COMMANDS
like above, that is silly. And when you add new deps inpackage,json
, you need to updatePRE_COMMANDS
,log info