ecoCode-javascript
ecoCode-javascript copied to clipboard
eslint-plugin: write rules in TypeScript
ESLint exports a package @types/eslint with typings of the whole linter. This can simplify the writing of rules with autocompletion and typing verification.
This idea has been proposed during the challenge, and I think it's a good idea to look into it. Maybe we should use it? What do you think of this?
Well, I both like and dislike TypeScript
TypeScript adds boilerplate that can quickly become cumbersome with added necessary build time Moreover, according to a well-knowned study (which would probably need an update), TypeScript was calculated as 4 times more energy consumming than JavaScript
Comparison to C
- JavaScript: 4.45x
- TypeScript: 21.5x
I usually prefered JSDoc where necessary. Nowadays, when IDEs don't do it natively, you should be able to also use TypeScript or the lighter flow to do typechecking and get autocompletion on regular JavaScript.
Both support "type inference" (which means that they detect the type of a variable / property based on the value it was initialized with)
TypeScript also supports part of JSDoc
Of course it's not as advanced as coding in TypeScript but energy impact and code complexity are lighter
See
- https://www.typescriptlang.org/docs/handbook/type-inference.html
- https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
The idea was to use TypeScript for the development of the plugin, but I agree that this will come with advantages and disavantages:
- ➕➕➕: TypeScript is typed by definition, so it will be much easier to write new rules. We are currently using JSDoc but this does not work very well in code editors and its hard to navigate through nodes without a lot of debugging.
- ➕➕: the code is also more reliable and more maintenable
- ➖: runtime code can be a bit more energy consumming (even if this is better as time goes - it builds more or less the same code as the JS one), but I think the main energy consumption happens during the build time, so not a big deal?
I understand your position but I think that the "ecological" cost of using TypeScript is not so bad, compared to the productivity boost.