kolint / next

Modern toolchain for enhancing usage of Knockout.js
https://kolint.github.io/next/
MIT License
1 stars 0 forks source link

Linter cli is always silent #9

Closed tscpp closed 3 months ago

tscpp commented 3 months ago

In that version the tool doesn't output anything and returns exit code 0. Even if I do some obvious mistake in a file it still doesn't output anything and exits with 0.

Originally posted by @ondrejmirtes in https://github.com/kolint/next/issues/8#issuecomment-2065348314

tscpp commented 3 months ago

I think I know why this is happening. If no inputs (positional arguments) are passed to the cli, by default nothing will match. The cli will exit with code 0 since no files are checked.

Update the package to latest beta release and try to run:

npx kolint path/to/view.html

Alternatively, configure an include and exclude pattern in config and run kolint on a directory (e.g. ./). Wait for me to fix #10 first.

kolint.config.js

export default {
  include: ["src/**/*.html"],
  exclude: ["**/node_modules"],
};

command-line

npx kolint .

@ondrejmirtes can you confirm?

ondrejmirtes commented 3 months ago

I was able to make it run, but it looks pretty broken. I used this config:

export default {
    include: ["frontend/**/*.html"],
    exclude: ["frontend/js/editor/*.html"],
};

But the error log has a lot of messages from node_modules which obviously I can't fix nor am I interested in them. Examples:

node_modules/JSV/examples/index.html:190:45 error KO0014 Expected 'Ident', '>', 'COLON', '/', 'bindAttr', got ";" (TEXT).
node_modules/JSV/jsdoc-toolkit/templates/bluelabel/static/index.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/JSV/jsdoc-toolkit/templates/codeview/static/header.html:1:0 error KO0002 Missing Viewmodel reference
node_modules/JSV/jsdoc-toolkit/templates/codeview/static/index.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/JSV/jsdoc-toolkit/templates/jsdoc/static/header.html:1:0 error KO0002 Missing Viewmodel reference
node_modules/JSV/jsdoc-toolkit/templates/jsdoc/static/index.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/JSV/tests/index.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/JSV/tests/index3.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/JSV/tests/index3b.html:1:11 error KO0014 Expected 'DOCEND', got "PUBLIC" (TEXT).
node_modules/colors/example.html:2:0 error KO0002 Missing Viewmodel reference

Even when I excluded files from the editor subdirectory, they are in the error log:

frontend/js/editor/ExpandMarkerTemplate.html:1:0 error KO0002 Missing Viewmodel reference
frontend/js/editor/ExpandWidgetTemplate.html:1:0 error KO0002 Missing Viewmodel reference
frontend/js/editor/IgnoredErrorsTemplate.html:1:0 error KO0002 Missing Viewmodel reference
frontend/js/editor/LineErrorTemplate.html:1:0 error KO0002 Missing Viewmodel reference
frontend/js/editor/LineErrorsTemplate.html:1:0 error KO0002 Missing Viewmodel reference

And from the rest of the codebase (from files I'm actually interested in) I'm getting a lot of errors like this:

frontend/index.html:38:151 error TS6133 'toggleUserMenu' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'hideUserMenu' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'relativePath' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'editorLink' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'openSettingsModal' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'openFeedbackForm' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'showPromoCodeExplanationModal' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'openAboutModal' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'playAnalysis' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'activeWindowAnalysis' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'pauseAnalysis' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'switchToWizards' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'switchToErrors' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'visible' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'templateName' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'templateData' is declared but its value is never read.
frontend/index.html:38:151 error TS6133 'allowClosing' is declared but its value is never read.
tscpp commented 3 months ago

@ondrejmirtes

The config file is not resolved unless the --config flag is explicitly set (bug #23). Try to run npx kolint -c kolint.config.js ... instead.

node_modules/ is by default not excluded (it should be #24). Add it to your config.

ondrejmirtes commented 3 months ago

Currently when I install @kolint/check it installs 0.4.0-beta.0 which is weird (?). I remember last time it installed beta.3 I think.

Right now if I try ./node_modules/.bin/kolint -c kolint.config.js . with kolint.config.js like this:

export default {
    include: ["frontend/**/*.html"],
    exclude: ["frontend/js/editor/*.html"],
};

The tool crashes with:

export default {
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1287:20)
    at Module._compile (node:internal/modules/cjs/loader:1339:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1434:10)
    at Module.load (node:internal/modules/cjs/loader:1206:32)
    at Module._load (node:internal/modules/cjs/loader:1022:12)
    at cjsLoader (node:internal/modules/esm/translators:358:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:307:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)

Node.js v21.5.0
ondrejmirtes commented 3 months ago

If I do this instead:

module.exports = {
    include: ["frontend/**/*.html"],
    exclude: ["frontend/js/editor/*.html"],
};

And run the tool, it shows basically the same output as in here https://github.com/kolint/next/issues/9#issuecomment-2069148196, including errors from files in node_modules.

tscpp commented 3 months ago

Currently when I install @kolint/check it installs 0.4.0-beta.0 which is weird (?). I remember last time it installed beta.3 I think.

For some reason the first beta release (0.4.0-beta.0) is tagged "latest", so if you run npm install @kolint/check then the tag "latest" is implied (@kolint/check@latest). You need to specify that you want the latest "beta" version npm install @kolint/check@beta.

The reason for SyntaxError: Unexpected token 'export' is because Nodejs detects the file as a CommonJS module. If the "type": "module" field is not set in package.json, all .js files will be detected as CommonJS modules. Use the "export default" syntax and rename the file to kolint.config.mjs and pass --config kolint.config.mjs.

Thanks for the feedback. I will include this in the documentation later.

cc @ondrejmirtes

ondrejmirtes commented 3 months ago

Alright, I did that, it installs beta 3, and the output is empty again. Even if I make an obvious mistake in a path that should be analysed (frontend/index.html). And it ends very fast. I think it doesn't see any files again.

tscpp commented 3 months ago

Alright, I did that, it installs beta 3, and the output is empty again. Even if I make an obvious mistake in a path that should be analysed (frontend/index.html). And it ends very fast. I think it doesn't see any files again.

Ok. I am totally sure what's happening. I need to do some refactoring and add a debug mode (to list the affected files, etc.).

ondrejmirtes commented 3 months ago

I installed beta 5 and still have the same behaviour. No output.

tscpp commented 3 months ago

Hopefully #34 fixed your issue by improving the config resolution algorithm. Else, the same pr introduced the --debug flag. If you could kindly update @kolint/check to 0.4.0-beta.6, and run the command with the --debug flag, I can better understand what is happening.

ondrejmirtes commented 3 months ago

Beta 6 works correctly (it finds the right files), even without --debug. I now get many errors like that (but only in the files I'm interested in, which is an improvement):

error: frontend/_includes/_alerts.html:19:97 error TS6133 'relativePath' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'editorLink' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'openSettingsModal' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'openFeedbackForm' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'showPromoCodeExplanationModal' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'openAboutModal' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'playAnalysis' is declared but its value is never read.
error: frontend/_includes/_alerts.html:19:97 error TS6133 'activeWindowAnalysis' is declared but its value is never read.

I see I ignored these errors in the original knockout-lint config too, what's the new severity syntax with @kolint/check? Thank you!

tscpp commented 3 months ago

@ondrejmirtes

Great that is it working! 🥳

This is how you would configure diagnostic severity:

export default {
  severity: {
    // Ex: disable ts error
    TS0000: "off",

    // Ex: disable linting error
    KO0000: "off",

    // Ex: warn on no viewmodel reference (instead of error)
    "no-viewmodel-reference": "warn"
  }
}

I'll add this to the docs later.

tscpp commented 3 months ago

I have improved the docs and added a guide to configure the severity: https://kolint.github.io/next/linting/config.html#severity.

If you have any questions, please open them at: https://github.com/kolint/next/discussions