Skip to content
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

feat: Add lint all feature to lint all the KCL code #1854

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Siddhi-agg
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

2. What is the scope of this PR (e.g. component or file name):

kcl/kclvm/tools/src/lint/mod.rs
kcl/kclvm/tools/src/lint/tests.rs

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other
    test case in kcl/kclvm/tools/src/lint/tests.rs

@Siddhi-agg
Copy link
Contributor Author

I have added a function which would lint all the .k files present, but I am not able to find the link between the cli command kcl lint and the function called after that (which must be lint_files right now). Please take a look.

CC: @Peefy @He1pa @zong-zhe

@He1pa
Copy link
Contributor

He1pa commented Feb 12, 2025

First of all, this problem is not about collecting all kcl files and then executing the lint command.
There are some differences between kcl and other languages.
The compilation scope of kcl (all compiled files) is composed of entry files and import files. So, even if some files are in the directory of kcl.mod but are not imported, these files will not be compiled.
I have made some work in lsp. You can refer to the difference between the functions parse_program() and load_all_files_under_paths() in https://github.com/kcl-lang/kcl/blob/main/kclvm/parser/src/lib.rs. The latter does something similar to you. We need to implement a function similar to lint_all_files_under_paths(), and call the original lint function and the new lint_all_files_under_paths according to the parameters of cli.

Finally, collect_kcl_files() is unnecessary, use get_files_from_path()

@Siddhi-agg
Copy link
Contributor Author

The compilation scope of kcl (all compiled files) is composed of entry files and import files. So, even if some files are in the directory of kcl.mod but are not imported, these files will not be compiled.
I have made some work in lsp. You can refer to the difference between the functions parse_program() and load_all_files_under_paths() in https://github.com/kcl-lang/kcl/blob/main/kclvm/parser/src/lib.rs. The latter does something similar to you. We need to implement a function similar to lint_all_files_under_paths(), and call the original lint function and the new lint_all_files_under_paths according to the parameters of cli.

Thank you for this explanation. I have understood the difference between the compilation scope and "all files" in KCL. I will work on correcting the implementation so that the new lint_all_files_under_paths() function lints the compilation scope as well as the non-imported files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants