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

refactor: Restructure linters #69

Merged
merged 5 commits into from
Apr 12, 2024
Merged

refactor: Restructure linters #69

merged 5 commits into from
Apr 12, 2024

Conversation

RandomByte
Copy link
Member

@RandomByte RandomByte commented Apr 9, 2024

This is our first major refactoring. Several concepts didn't play out
the way we initially thought, and that's ok.

Highlights are:

  • Reporters shall no longer produce actual "reports" but rather
    create "LintMessages" and "CoverageInfo"
  • Linters become more independent but share a common signature
    ("LinterParameters")
  • Linters access and share resources via a @ui5/fs
    "workspace" instance. Resource paths reflect UI5 runtime paths
  • Linters are generally async and executed concurrently
    (eventually in workers if we can proof performance improvements)
  • A LinterContext instance is proveded to all linters.
    • Linters provide it with their produced "LintMessages" and
      "CoverageInfo" from which the final "LintResult" is generated.
  • The "ui5Types"-Linter is special and executed after all other linters
    have finished (to take any transpiled resources into account)

Architecture Overview

overview_draft_PR69

Performance

I compared the current main (70b719a) branch with commit 881cdb2 of this branch for linting sap.m for OpenUI5 tag 1.120.10

Command Mean [s] Min [s] Max [s] Branch
ui5lint 32.031 ± 0.798 31.508 34.205 main
ui5lint 32.845 ± 0.770 31.694 34.289 This PR
ui5lint --file-paths src/sap/m/Table.js 14.675 ± 0.316 14.109 15.190 main
ui5lint --file-paths src/sap/m/Table.js 2.267 ± 0.024 2.236 2.308 This PR

@RandomByte
Copy link
Member Author

I'll look into the test failures on Windows later today

@RandomByte RandomByte marked this pull request as ready for review April 11, 2024 08:08
Comment on lines +19 to +23
await Promise.all([
lintXml(params),
lintJson(params),
lintHtml(params),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the former implementation those were returning the transpiled source code, messages and source maps.

We might need those in the future as we would like to eventually analyze html's script content, build & check code against manifest.json directives etc.

I'm not sure I understand how this is addressed in that PR.
Currently the TypeLinter checks for js/ts files and analyzes them. However, I'm missing the mechanism that would bring the transpiled html resources, for example to that analysis there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

@RandomByte RandomByte Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an example, have a look at the XML-Linter in this PR:
https://github.com/SAP/ui5-linter/pull/69/files#diff-1bc919fd57fdbc38b20c5feaca329ba1764224846e55d4a8b7b654f18e9ca35cR29-R40

The transpiled resources are written to the workspace from where the TypeLinter will later read them together will all other ".js" resources.

The association back to the original (XML)-Resource is done by reading the original file name from the "sources" array of the associated source map in the TypeLinter's reporter: https://github.com/SAP/ui5-linter/pull/69/files#diff-1a8fcfb41f5f0e0d7d87295b6290a8af77f0d01a7881196967276fa790410ebbR148

I think the same can be applied for the HTML linter:

  1. src/linter/html/transpiler.ts returns one or more JavaScript + SourceMap pairs
  2. src/linter/html/linter.ts creates @ui5/fs/Resource instances and writes them to the workspace
  3. TypeLinter picks them up with all the other JS files

@RandomByte RandomByte force-pushed the refactor-linter-modules branch 2 times, most recently from 12df583 to 583e026 Compare April 11, 2024 14:24
Copy link
Contributor

@d3xter666 d3xter666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

flovogt
flovogt previously approved these changes Apr 12, 2024
This is our first major refactoring. Several concepts didn't play out
the way we initially thought, and that's ok.

Highlights are:
* Reporters shall no longer produce actual "reports" but rather
  create "LintMessages" and "CoverageInfo"
* Linters become more independent but share a common signature
  ("LinterParameters")
* Linters access and share resources via a @ui5/fs
  "workspace" instance. Resource paths reflect UI5 runtime paths
* Linters are generally async and executed concurrently
  (eventually in workers if we can proof performance improvements)
* A LinterContext instance is proveded to all linters.
    * Linters provide it with their produced  "LintMessages" and
      "CoverageInfo" from which the final "LintResult" is generated.
* The "ui5Types"-Linter is special and executed after all other linters
  have finished (to take any transpiled resources into account)
* Use "ResourcePath" for virtual paths (= always POSIX)
* Use "FilePath" for physical FS paths (POSIX or Windows)
@RandomByte RandomByte merged commit 5abbfc1 into main Apr 12, 2024
16 checks passed
@RandomByte RandomByte deleted the refactor-linter-modules branch April 12, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants