SAP / ui5-linter

A static code analysis tool for UI5
Apache License 2.0
40 stars 0 forks source link

Integrate with ESLint #45

Open RandomByte opened 3 months ago

RandomByte commented 3 months ago

Requirement

Provide an ESLint plugin to easily integrate UI5 linter checks into existing development workflows.

Challenges

Or why this was not our initial design goal

Proposal

mauriciolauffer commented 3 months ago

Challenges

Proposal

PS: I'm sorry if this sounds too harsh, but I've spoken to multiple SAP developers working on real projects, and nobody could understand why or see the value in this new linting tool...

codeworrior commented 3 months ago

I think this is a big misunderstanding. For sure, ESLint is the 1st choice for linting JavaScript / TypeScript and its other derivates. The UI5 linter doesn't want to replace ESLint. It therefore won't get rules that exist already in ESLint or better could be added there (the linter's repository might in fact become the home for such rules / for a UI5 specific ESLint plugin, should we decide to implement it)..

And yes, the UI5 linter contains several custom parsers.

But that's not the point. There's one big difference to ESLint rules and @RandomByte already explained it above. To reliably find usages of deprecated APIs, it's not sufficient to scan a local AST as ESLint rules do. You have to build up a project-wide understanding of types to judge whether a getProperty call is a ManagedObject.prototype.getProperty call (not deprecated) or a v4.ODataModel.property.getProperty call (deprecated). This is something you don't get from ESLint yet (please read the ESLint issue #16819 linked above).

For sure, we could find ways to bypass this, creating a project view on our own and accessing it from within our rules. But that's a substantial development effort (I'll come to this in a second). And there's no guarantee that such an approach then will survive a major version update of ESLint (multi threaded execution of rules which works well with isolated AST-visiting rules, but obviously adds additional effort for shared project information). If ESLint doesn't provide a way to maintain a project view, we're at risk that our workaround doesn't work anymore.

Reg. the effort: one of the major requirements for the UI5 linter was a quick availability. That's why substantial development efforts was not so weird as a counter argument from our point of view. We therefore decided not to re-invent the wheel and rather integrate with the TypeScript compiler.

You might argue that we at least could integrate all those checks that can be implemented on a per-file base as ESLint rules. That's true, but at least currently we think it's more beneficial for UI5 developers if a single tool helps them to identify UI5 specific potential for improvement in their code.

Last but not least, if we later find out that our requirements regarding the code scans are fufilled by a newer ESLint version, we will check if / how we can integrate into it.

Again, UI5 linter isn't there to replace ESLint, it's rather an addition (additional tool). Maybe, from that point of view, the name choice was a bit misleading (it's rather a UI5 deprecation and best practice checker). But we thought that the term "linter" is so familiar to developers that it's the best choice to explain the purpose of the tool.