-
-
Notifications
You must be signed in to change notification settings - Fork 838
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
Add ESLint #643
Comments
I agree this could be better, but a balance is necessary to encourage both consistency and creativity. There's nothing worse than getting into flow with an idea and then fighting with types or linters that are so strict that they cause you to stumble. 😅 For example, I usually type things as I go, but sometimes (especially with third party types I'm less familiar with) I plow through it to make sure the concept works before spending too much time on types. I'd hate to lose this ability.
I'm OK with doing this as long as it's done cleanly through esbuild. Per this and this, it looks like it's possible with path aliasing in tsconfig. I don't want to introduce another build tool at this time.
Let's hold off on this one for now.
I'd be interested to see how well the codebase fairs against this rule, so let's enable it and see.
I've been sticking to private fields only because it got super verbose along with decorators, types, JSDoc comments, etc. I'm probably missing a few
I'm OK with forbidding this. There aren't that many in the project, but there are some that need to be updated.
Sure, let's give it a go.
Totally fine. Preferably it will update the order on save (can Prettier do this?) so you don't have to do it manually.
Yeah, we don't want them being committed. At the same time, when I'm developing locally, if I knowingly "break" types to test something out, I still want it to rebuild. This is how it currently works with esbuild (because it discards types) so those things are currently caught by TypeScript. Basically I'm fine showing the errors via ESLint and stopping the build, but it shouldn't hinder local dev as temporary breakages are often intentional.
For sure. Thanks again for taking the time to sort through this and offer your thoughts! |
Yup totally! I'll make sure that this doesn't impact development. This should only be enforced on commit and on PR. During development you can do whatever you want as long as it complies by the time it's done. :)
I'll try this out and see if it's easy enough to add without impacting anything. This will be TBD on implementation difficulties.
The naming convention rule is super customizable. Do you have any rules which we should try to enforce or should I just try to reverse engineer what is currently there and standardize on whatever is the most common currently?
ESLint has a With your answers to the above, I should have enough to get started. Thanks for your support! |
I was thinking standardize what's there/common. Let me know if you need anything else! |
Status update: I'm still chugging away. I think there were about 2,000 errors/warnings when I started, now we are down to about 800. So definite progress being made. This is going to be a massive PR since it touches basically every file. One weird thing that I encountered for which I'm proposing a functionality change (minor) is that the Here's the snippet of relevant code to help explain the change to
|
Just a heads up...I noticed form controls were rendering strangely (notice the extra margin on top): I traced it to this code in const hasLabel = typeof props.label !== 'undefined' ? true : props.hasLabelSlot === true;
const hasHelpText = typeof props.helpText !== 'undefined' ? true : props.hasHelpTextSlot === true; The original code looked like this: const hasLabel = props.label ? true : !!props.hasLabelSlot;
const hasHelpText = props.helpText ? true : !!props.hasHelpTextSlot; They aren't equivalent. While the latter violates a couple of the new lint rules, it works as expected whereas the new condition fails due to the stricter This was one of the concerns I had with enabling this rule, verbosity being the other. I'll dive deeper into testing to make sure we don't introduce any regressions due to similar logic updates. |
Oh no! I feel awful. I assure you that the motivation for these changes was to make it better and safer, not worse. I apologize. I'm sorry you've had to revert a good portion of it. Let me know if there's anything you need from me. |
No worries. It was only two or three rules and a handful of associated lines. Everything else is fantastic! I didn’t write this to chastise your efforts. I figured it would be worth mentioning to make future refactors (here or anywhere you contribute) more smooth. And also in case you were wondering why the affected lines got reverted. You’ve nailed a few really solid PRs and I’m very thankful for your contributions! |
What issue are you having?
As a newcomer to the project, it's hard to figure out what the correct coding style is and best practices. When looking around the files, I see different approaches for the same thing. (eg: a few functions have explicit return types, others don't. Sometimes named functions use arrow-syntax and others function keyword. Type imports are sometimes imported with
import type
and other times not.) As a result, it's confusing when jumping into the code base as it's unclear what standards to follow.Another big area of difficulty is the usage of loose TypeScript types such as
any
throughout the codebase. If you don't realize a variable you are working with isany
you may write code that passes validations but fails at runtime.It would also be nice to have additional warnings regarding some of the specific tools used (lit, web components, chai) to be able to warn me against easy errors like forgetting to remove my event listeners or writing invalid HTML in template strings.
Describe the solution you'd like
I'd like the library to setup ESLint to enforce consistent code (both style and functionality).
Describe alternatives you've considered
I could create PRs and wait to be told by the maintainers that my code isn't correct, or be responsible for bugs due to errors I've introduced without realizing. Honestly though, it'd be easier to not contribute to the library as I feel like I'm too likely to screw something up if I make a change.
ESLint specifics
I'd like to add ESLint to this package and use this issue thread to discuss any controversial rule decisions along the way. Here's a few of the larger (possibly controversial) decisions to decide upfront if we are to do this.
~/
to referencesrc/
and then add the ESLint rules to prohibit any../*
imports. The benefit would be much clearer import paths instead of traversing up the tree and easier refactoring as the paths are not parent-relative. A downside is the added build complexity (which would be solved by a bundler like Rollup/Webpack, but I'm not sure about ESBuild.private
,public
, orprotected
.any
(to be replaced withunknown
or a better type when possible)? Similarly, prohibit other types which aren't as strict or accurate as they might seem (like:Function
,{}
,Object
, etc)true
/false
, not any truthy/falsy value. And you must useparseInt
,.toString()
, etc to convert between types rather than implicitly with operators like+
.And all of these decisions are not permanent. If a rule becomes a pain it can be changed or removed. If there are cases where it doesn't apply but is generally useful, it can be disabled with a comment in the code. As long as these changes provide benefit and security overall, they are going to pay for themselves!
The text was updated successfully, but these errors were encountered: