-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue in TYPESCRIPT-ES when using mega-lint-runner #1572
Comments
This is a stab in the dark, but what happens if you remove the I'm not sure whether or not this will be helpful to you, but perhaps it will be helpful to others. I haven't run into this issue in our TypeScript projects, because we use Prettier. See ScribeMD/docker-cache for an example of a working MegaLinter + TypeScript config. |
Anyways, I did the following - Case 1ESlint config{
"extends": ["eslint-config-airbnb-base", "eslint-config-airbnb-typescript/base"],
"parserOptions": {
"project": ["./tsconfig.json", "./tsconfig.eslint.json"]
},
"rules": {
"no-console": "off"
}
} Mega linter config# Configuration file for MegaLinter
# See all available variables at https://megalinter.github.io/configuration/ and in linters documentation
APPLY_FIXES: all # all, none, or list of linter keys
# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default
# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
DISABLE:
- GIT
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
# - SPELL # Uncomment to disable checks of spelling mistakes
DISABLE_LINTERS:
- JAVASCRIPT_STANDARD
- TYPESCRIPT_STANDARD
SHOW_ELAPSED_TIME: true
FILEIO_REPORTER: false
# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass
JAVASCRIPT_DEFAULT_STYLE: prettier
TYPESCRIPT_DEFAULT_STYLE: prettier
LINTER_RULES_PATH: .
PRINT_ALPACA: false
PRE_COMMANDS:
- command: 'npm install'
cwd: 'workspace'
POST_COMMANDS:
- command: 'npm run pretty'
cwd: 'workspace'
IGNORE_GITIGNORED_FILES: true
# Excludes cspell file itself
SPELL_MISSPELL_FILTER_REGEX_EXCLUDE: cspell. Result
Log file shows same error text as attached in the first comment of the issue. Case 2:ESlint configSame as in Case 1 Mega linter# Configuration file for MegaLinter
# See all available variables at https://megalinter.github.io/configuration/ and in linters documentation
APPLY_FIXES: all # all, none, or list of linter keys
# ENABLE: # If you use ENABLE variable, all other languages/formats/tooling-formats will be disabled by default
# ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
DISABLE:
- GIT
# - COPYPASTE # Uncomment to disable checks of excessive copy-pastes
# - SPELL # Uncomment to disable checks of spelling mistakes
DISABLE_LINTERS:
- JAVASCRIPT_STANDARD
- TYPESCRIPT_STANDARD
SHOW_ELAPSED_TIME: true
FILEIO_REPORTER: false
# DISABLE_ERRORS: true # Uncomment if you want MegaLinter to detect errors but not block CI to pass
JAVASCRIPT_DEFAULT_STYLE: prettier
TYPESCRIPT_DEFAULT_STYLE: prettier
LINTER_RULES_PATH: .
PRINT_ALPACA: false
#PRE_COMMANDS:
# - command: 'npm install'
# cwd: 'workspace'
#POST_COMMANDS:
# - command: 'npm run pretty'
# cwd: 'workspace'
IGNORE_GITIGNORED_FILES: true
# Excludes cspell file itself
SPELL_MISSPELL_FILTER_REGEX_EXCLUDE: cspell. ResultSame as Case 1 + There are git diffs in some files, because ESlint couldn't "fix" them Case 3ESlint config{
"extends": ["eslint-config-airbnb-base", "eslint-config-airbnb-typescript/base"],
"parserOptions": {
"project": ["tsconfig.json", "tsconfig.eslint.json"]
},
"rules": {
"no-console": "off"
}
} Mega linter configSame as Case 2 ResultSame as Case 2 VerdictEven after removing I wonder if the issue is about that |
Forgot to mention this - $ docker --version
Docker version 20.10.16, build aa7e414
$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c I'm using Windows 11 pro, Docker is using WSL 2. The issue affects me locally only, so I'm fine if no definite solution is found as long as it works properly as Github Action |
Now I'm doubly glad you filed this bug, because I just realized that we haven't been running ESLint at all, which explains why we didn't experience this issue. (We don't use the GitHub Action.) When I create a TYPESCRIPT_ES_PRE_COMMANDS:
- command: npm install <missing dependencies, such as your base tsconfig> Setting On a side note, if I understood correctly, you are saying that ESLint and Prettier are configured in such a manner that they potentially contradict each other, which sounds problematic. Please see Prettier's guidance on playing nicely with ESLint. You can also configure many editors to run many linters on save. I do think this issue needs to be fixed, and I'm making it my current active work item because the present work around is so unacceptable long-term. |
@MRDGH2821, we still need to fix the underlying bug, but hopefully this improved workaround gets you unblocked for the time being. I recommend adding the following to your MegaLinter config: TYPESCRIPT_ES_CLI_LINT_MODE: project This causes ESLint to be run on the entire project rather than be passed each individual file, so if your project has a lot of files, this will unfortunately slow things down. You probably won't even need to use When I run ESLint outside of MegaLinter in the same project, I don't experience the same issue, so I am pretty confident this is our bug. I debugged this issue by passing
With the lint mode overridden from the default of
This, in conjunction with the error you initially reported, implies that ESLint is not run with the correct working directory in |
The code formatted by prettier triggers eslint errors. Adding this line into the config worked for me in local & github action both. TYPESCRIPT_ES_CLI_LINT_MODE: project
If there's a way to utilise multiple CPU cores then I would like to know. Else slow speed not much of an issue. On top of that I won't be linting the files when the code goes live in production 😂 Thanks for the temporary fix! |
Sorry I overlooked your lingering question here. Unfortunately, beyond that you upvote eslint/eslint#3565, I don't have a great suggestion for you. @nvuillam may correct me if I am mistaken, but my understanding is that MegaLinter runs the linter once in |
That brings us back to #1544 :) |
This issue has been automatically marked as stale because it has not had recent activity. If you think this issue should stay open, please remove the |
I think this issue : ESLint :: #440 : Swiftlint. |
Hello, face the same issue with
|
Do you have a |
Yeah sure, initially we used |
Thank you for confirming; in retrospect that should have been obvious, but I am doing a bit too much context switching right now. This doesn't solve your problem, but |
Thank you for the quick response, just want to mention that I tried to use |
.eslintrc.json file: {
"root": true,
"parser": "@typescript-eslint/parser",
"ignorePatterns": ["**/jest.config.ts", "**/jest.preset.ts", "**/custom.d.ts"],
"plugins": [
"@typescript-eslint",
"rxjs",
"rxjs-angular"
],
"parserOptions": {
"project": "tsconfig.json"
},
"extends": [
],
"rules": {
// basic rules
"prefer-const": "error",
"rxjs-angular/prefer-takeuntil": [
"error",
{
"alias": ["untilDestroyed"],
"checkComplete": true,
"checkDecorators": ["Component"]
}
],
"@typescript-eslint/no-useless-constructor": "error",
"max-lines-per-function": ["error", { "max": 35 }],
"no-param-reassign": "error",
"indent": ["error", 2, {"SwitchCase": 1}],
"semi": ["error", "always", { "omitLastInOneLineBlock": true}],
"no-template-curly-in-string": "error",
"prefer-template": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
],
"@typescript-eslint/no-extraneous-class": ["error", {
"allowWithDecorator": true
}],
"@typescript-eslint/no-this-alias": [
"error",
{
"allowDestructuring": false
}
],
// typescript strict null check required
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/explicit-function-return-type": ["error"],
"@typescript-eslint/consistent-type-assertions": [
"error",
{
"assertionStyle": "never"
}
],
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "default",
"format": ["camelCase"],
"leadingUnderscore": "allow",
"trailingUnderscore": "forbid"
},
{
"selector": "variable",
"format": ["camelCase", "UPPER_CASE"],
"leadingUnderscore": "allow",
"trailingUnderscore": "forbid"
},
{
"selector": "variable",
"modifiers": ["destructured"],
"format": null
},
{
"selector": "typeProperty",
"format": ["camelCase", "PascalCase", "UPPER_CASE"]
},
{
"selector": "objectLiteralProperty",
"format": null
},
{
"selector": ["typeLike", "enumMember"],
"format": ["PascalCase"]
}
],
// compact - better reading
"max-len": [
"error",
{
"code": 120,
"ignoreUrls": true,
"ignoreStrings": true
}
],
"max-lines": ["error", 500],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/typedef": [
"error",
{
"variableDeclaration": true,
"objectDestructuring": true,
"variableDeclarationIgnoreFunction": true
}
],
// clear trash
"no-trailing-spaces": "error",
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/no-extra-non-null-assertion": "error",
"@typescript-eslint/no-empty-interface": [
"error",
{
"allowSingleExtends": false
}
],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-confusing-non-null-assertion": "warn",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-console": "error",
"no-empty": "error",
"no-sequences": "error",
"no-sparse-arrays": "error"
}
} |
Thanks; that's helpful, but unfortunately I have more questions than answers for you. The original error was On a side note, I suspect you should have |
package.json {
"name": "project-frontend",
"license": "MIT",
"scripts": {
"dep-graph": "nx dep-graph",
"start:prod": "nx run project:serve:development --proxyConfig=tools/proxies/prod.json --live-reload",
"start:dev1": "nx run project:serve:development --proxyConfig=tools/proxies/dev1.json --live-reload",
"start:demo2": "nx run project:serve:development --proxyConfig=tools/proxies/demo2.json --live-reload",
"postinstall": "node ./decorate-angular-cli.js && ngcc --properties es2015 browser module main",
"build": "nx build --deploy-url=/tasks/ --base-href=/tasks/",
"test": "nx test",
"ng": "nx",
"lint": "eslint . --ext .ts",
"prettier:check-diff": "prettier --config .prettierrc.json -c $(git diff HEAD --relative --name-only --diff-filter d | grep -E './**/*.(html|ts)' | xargs) --ignore-unknown",
"prettier:fix-diff": "prettier --config .prettierrc.json -w $(git diff HEAD --relative --name-only --diff-filter d | grep -E './**/*.(html|ts)' | xargs) --ignore-unknown",
"prettier:check-all": "prettier --config .prettierrc.json -c ./**/*.ts ./**/*.html --ignore-unknown",
"prettier:fix-all": "prettier --config .prettierrc.json -w ./**/*.ts ./**/*.html --ignore-unknown",
"start:production": "nx run project:serve:production"
},
"private": true,
"dependencies": {
"@angular/animations": "13.3.8",
"@angular/cdk": "13.3.7",
"@angular/common": "13.3.8",
"@angular/compiler": "13.3.8",
"@angular/core": "13.3.8",
"@angular/forms": "13.3.8",
"@angular/platform-browser": "13.3.8",
"@angular/platform-browser-dynamic": "13.3.8",
"@angular/router": "13.3.8",
"@ant-design/icons": "^4.7.0",
"@ant-design/icons-angular": "^13.1.0",
"@auth0/angular-jwt": "~5.0.2",
"@frontend-libs/cdk": "2.0.4",
"@frontend-libs/functions": "~2.0.1",
"@frontend-libs/kit": "2.0.2",
"@frontend-libs/pipes": "2.0.2",
"@frontend-libs/redesign-kit": "0.0.53",
"@ngneat/hot-toast": "4.1.0",
"@ngneat/transloco": "2.23.2",
"@ngneat/until-destroy": "~9.2.0",
"@ngxs/store": "^3.7.3-dev.master-b00eeb3",
"@nrwl/angular": "^14.5.6",
"@tiptap/extension-blockquote": "^2.0.0-beta.209",
"@tiptap/extension-bold": "^2.0.0-beta.209",
"@tiptap/extension-bullet-list": "^2.0.0-beta.209",
"@tiptap/extension-character-count": "^2.0.0-beta.26",
"@tiptap/extension-code": "^2.0.0-beta.199",
"@tiptap/extension-code-block-lowlight": "^2.0.0-beta.199",
"@tiptap/extension-color": "^2.0.0-beta.9",
"@tiptap/extension-document": "^2.0.0-beta.209",
"@tiptap/extension-dropcursor": "^2.0.0-beta.209",
"@tiptap/extension-gapcursor": "^2.0.0-beta.209",
"@tiptap/extension-hard-break": "^2.0.0-beta.209",
"@tiptap/extension-heading": "^2.0.0-beta.209",
"@tiptap/extension-history": "^2.0.0-beta.209",
"@tiptap/extension-horizontal-rule": "^2.0.0-beta.209",
"@tiptap/extension-image": "^2.0.0-beta.27",
"@tiptap/extension-italic": "^2.0.0-beta.209",
"@tiptap/extension-link": "^2.0.0-beta.38",
"@tiptap/extension-list-item": "^2.0.0-beta.209",
"@tiptap/extension-ordered-list": "^2.0.0-beta.209",
"@tiptap/extension-paragraph": "^2.0.0-beta.209",
"@tiptap/extension-placeholder": "^2.0.0-beta.209",
"@tiptap/extension-strike": "^2.0.0-beta.209",
"@tiptap/extension-subscript": "^2.0.0-beta.10",
"@tiptap/extension-superscript": "^2.0.0-beta.10",
"@tiptap/extension-table": "^2.0.0-beta.49",
"@tiptap/extension-table-cell": "^2.0.0-beta.20",
"@tiptap/extension-table-header": "^2.0.0-beta.22",
"@tiptap/extension-table-row": "^2.0.0-beta.19",
"@tiptap/extension-task-item": "^2.0.0-beta.199",
"@tiptap/extension-task-list": "^2.0.0-beta.199",
"@tiptap/extension-text": "^2.0.0-beta.209",
"@tiptap/extension-text-align": "^2.0.0-beta.29",
"@tiptap/extension-text-style": "^2.0.0-beta.23",
"@tiptap/extension-typography": "^2.0.0-beta.20",
"@tiptap/extension-underline": "^2.0.0-beta.23",
"@typescript-eslint/parser": "^5.18.0",
"lowlight": "^2.7.0",
"ng-zorro-antd": "~13.3.2",
"ngx-scrollbar": "^8.0.0",
"ngx-tippy-wrapper": "^5.0.2",
"ngx-tiptap": "^5.0.0",
"npx": "^10.2.2",
"rxjs": "^7.5.5",
"tslib": "~2.3.1",
"turndown": "^7.1.1",
"uuid": "^8.3.2",
"zone.js": "0.11.5"
},
"devDependencies": {
"@angular-builders/custom-webpack": "~13.1.0",
"@angular-devkit/build-angular": "13.3.5",
"@angular-eslint/builder": "~13.2.1",
"@angular-eslint/eslint-plugin": "~13.2.1",
"@angular-eslint/eslint-plugin-template": "~13.2.1",
"@angular-eslint/schematics": "~13.2.1",
"@angular-eslint/template-parser": "~13.2.1",
"@angular/cli": "13.3.5",
"@angular/compiler-cli": "13.3.8",
"@angular/language-service": "13.3.8",
"@ngxs/devtools-plugin": "^3.7.4",
"@nrwl/cli": "^14.5.6",
"@nrwl/cypress": "^14.5.6",
"@nrwl/eslint-plugin-nx": "^14.5.6",
"@nrwl/jest": "^14.5.6",
"@nrwl/linter": "^14.5.6",
"@nrwl/workspace": "^14.5.6",
"@types/jest": "27.4.1",
"@types/node": "16.11.7",
"@types/turndown": "^5.0.1",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "~5.18.0",
"cypress": "^9.1.0",
"eslint": "~8.12.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-cypress": "^2.10.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.4.6",
"eslint-plugin-jsdoc": "^39.3.2",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-rxjs": "^5.0.2",
"eslint-plugin-rxjs-angular": "^2.0.0",
"eslint-plugin-unicorn": "^42.0.0",
"file-loader": "^6.2.0",
"jest": "27.5.1",
"jest-preset-angular": "11.1.1",
"nx": "^14.1.4",
"prettier": "^2.7.1",
"raw-loader": "~4.0.2",
"ts-jest": "27.1.4",
"ts-node": "~10.4.0",
"typescript": "^4.6.4",
"typescript-strict-plugin": "^2.0.0"
}
} |
|
I will tell FrontendDevs regarding this thank you :) |
I believe |
Confirm,
here is the example of my tsconfig.json {
"extends": "./tsconfig.base.json",
"compilerOptions": {
"alwaysStrict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"strictBindCallApply": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"noImplicitOverride": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"suppressExcessPropertyErrors": true,
"suppressImplicitAnyIndexErrors": true
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
} |
That looks reasonable to me. I would try again with |
In project mode, ESLint succeeds without doing anything when called without any files, so pass it the current directory.
My hack trying to use |
In project mode, ESLint succeeds without doing anything when called without any files, so pass it the current directory.
I am moving this discussion from #2578, where this is the third of three issues, to this thread. If you've already read that thread, this will be redundant, but I will summarize it for those who haven't. The root cause of the issue I reported on the other thread is related to the way we install our Node.js dependencies, namely to POST_COMMANDS:
- command: rm -r node_modules
cwd: workspace
TYPESCRIPT_ES_PRE_COMMANDS:
- command: npm install @tsconfig/[email protected]
- command: cp --recursive /node-deps/node_modules/ node_modules
cwd: workspace One thing that would potentially make this all better would be supporting arrays in the |
Copied from #2578:
@nvuillam, #2601 does not fix the issue and breaks the workaround. I tried adapting the workaround I described above by specifying
Leaving the workaround as-is results in the same crash on
|
@Kurt-von-Laven thanks for the feedback The goal is to be able to perform npm install, yarn install, npm install xxx-dep or yarn add xxx-dep in PRE-COMMANDS without any workaround, don't worry i don't plan to release a new ML version before that :) There was a bug, and i also added dir_exists_ok =True in another PR, it might work better |
Pre/post-commands containing |
Everything changes since all commands are called from workspace and not from docker image root, there are more advantages than inconveniences to call linters the same way they would be locally. I'm currently working on your idea to allow to override cli_executable |
Changing the default working directory of pre-commands from |
@Kurt-von-Laven I'm trying again something else... :) Would it be acceptable to say that if there are additional npm dependencies:
|
That sounds promising! |
@Kurt-von-Laven I think i have found the solution, published in the newest beta ! :) --> https://github.com/nvuillam/CSpell-Bug/tree/nico (additional cspell dict is well added, without copying node_modules or messing with PATH) Job with GHA: https://github.com/nvuillam/CSpell-Bug/actions/runs/4854021395/jobs/8650882718?pr=1 Job with mega-linter-runner: https://github.com/nvuillam/CSpell-Bug/actions/runs/4854021390/jobs/8650882471?pr=1 Please can you try by using |
Running
|
I hit the same TYPESCRIPT_ES_PRE_COMMANDS:
- command: npm install @tsconfig/[email protected]
continue_if_failed: false
cwd: /node-deps When I use Copying |
@Kurt-von-Laven did you pull the latest beta ? |
Yeah, sorry, I think I was under the impression when I wrote that that the |
@Kurt-von-Laven with newest beta, NODE_PATH and PATH remain untouched, NODE_PATH is /node-deps and PATH still has /node-deps/node_modules |
@Kurt-von-Laven I'm trying to add a test case, do you have suggestions about how it should be built ? I'm trying that, probably it needs an additional package.json, maybe a 'yarn' to install dependencies as pre-command ? |
That is a great idea! In an empty directory, one can run |
One issue I expect this test will expose is that |
|
Describe the bug
When using mega-lint-runner,
TYPESCRIPT_ES
always fails to lint, because it is not able to access/tsconfig.json
Where as in Github Actions, there is no error for the same.
Expected behavior
TYPESCRIPT_ES
should have thrown error or success flag on both CI & local, but it is not happenning.Screenshots
Here is the log file instead
ERROR-TYPESCRIPT_ES.log
Additional context
My repository where it is enabled - https://github.com/MRDGH2821/Perpetual-Mechanical-Array-Bot/tree/rewrite-detritus-bug-hunt
Branch -
rewrite-detritus-bug-hunt
The configurations are at root of the directory.
.eslintrc.json -
tsconfig.json -
The text was updated successfully, but these errors were encountered: