-
Notifications
You must be signed in to change notification settings - Fork 492
Consider relaxing lint rules #333
Comments
Hi! Thanks for stopping by. I just responded to the thread #329 addressing this. General gist is I'm happy for someone to make a copy of the rules from CRA to provide a more similar experience. |
For inspiration, here is the CRA lint config: |
Happy to take a crack at this. :) |
In particular, note that we don't use |
I should also mention the problem I ran into in my project (I just started to use TypeScript recently): I had to add another TS config for production, since I don't want unused variables to be treated as errors in development (just as warnings), but on the other side, there is no way to build production version (or lint on precommit) with zero tolerance for warnings, there has to be an error. |
I can work on this. |
The way it works now, rules aren’t loaded at all from This file includes the @wmonk any preference here? I think that removing the |
Just keep in mind that the current |
Any person who thinks ordering imports is important probably already has opinions about TSLint config and will configure it themselves anyway. So we might as well relax the default for the people who don't necessarily find something like this "messy style" and just want to get the work done. |
A setting in This will report lint errors as warnings during development ( For reference our {
"extends": ["tslint:recommended", "tslint-react", "tslint-config-prettier"],
"linterOptions": {
"exclude": ["config/**/*.js", "node_modules/**/*.ts"]
},
"rules": {
"arrow-parens": false,
"eofline": false,
"interface-name": false,
"jsx-boolean-value": false,
"jsx-no-lambda": false,
"jsx-no-multiline-js": false,
"member-access": false,
"no-return-await": false,
"no-submodule-imports": false,
"no-trailing-whitespace": false,
"no-var-requires": false,
"object-literal-sort-keys": false,
"only-arrow-functions": false,
"ordered-imports": false,
"prefer-conditional-expression": false,
"semicolon": [true, "always", "ignore-bound-class-methods"],
"trailing-comma": false,
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-leading-underscore",
"allow-pascal-case"
]
},
"defaultSeverity": "warning"
} |
@anantoghosh are you working on a PR for this? |
@wmonk No, I thought @filipdanic is working on it. |
@anantoghosh @filipdanic If you don't start this soon, i will. Don't wait for one another, just do it! 😛 @wmonk simply relaxing a few rules and Do you know otoh why that is? |
Don't mix |
While this seems to be the case, i think it goes hand in hand with adjusting tslint configuration. I don't want this to stop my development server, but a warning in the editor of choice and/or the build process would be fine so we could decide how to deal with this in CI environments. |
Feel free to do so - just disable the compiler option in
There is a major difference between the linter and the compiler: |
@DorianGrey let's find a reasonable way around that limitation, then. It's not helpful to not see any warnings in development and have it break in production build on CI later on. Visual Studio code for example, underlines an unused variable with a green warning line when
|
You could also use the tslint equivalent and leave the compiler option disabled. |
@ianschmitz sounds like the better alternative. Which tslint option is that? |
This is the closest one: https://palantir.github.io/tslint/rules/no-unused-variable/. However note that because it requires type info, if you're using the VSCode TSLint extension, it doesn't display linting errors that require type info. See https://github.com/Microsoft/vscode-tslint/blob/master/tslint/README.md#faq |
Warning: typescript newbie here. Relaxing rules in This is crazy. Preventing the app from even compiling because of a lint rule about a empty function block, or another lint rule about keys in an object literal not being sorted alphabetically is crazy. But well, back to my issue: when I got the problem about the empty function block, I disabled that rule in the My point is, if there's something really useful in that IMO, if this is supposed to be a sister project to CRA, it should provide a similar initial linting experience than CRA. That is, warn only about things that are really clearly not good. Unused variables, unreachable code, things like that. And also, please, do not make them compile errors when possible. Just warnings in the browser console and the terminal. Other than all that, great initiative, typescript is awesome! |
@gnapse refer to my comment above at #333 (comment) |
Thanks! That solves the compile errors. But what about the fact that setting the rule as false did not work, but fixing the code to satisfy the rule did work? To be clear, I had linting errors initially on .tsx files, and as soon as I switch them off in the tslint.json file, the editor (vscode) removes the warning in the code. But with javascript files, I never got a warning in code, I only get the compile error, and switching the rule off still gives me the compile error. Seems like the linting performed by the editor is not the same as the linting performed during |
just writing in from the /r/reactjs subreddit where i have been helping people get started with react + typescript. here's someone with 2 years exp in react running in to this issue: https://www.reddit.com/r/reactjs/comments/8o5owb/react_typescript_cheatsheet_for_react_users_using/e1jzh2x/?context=3 |
I think our most beginner friendly option is to switch back to CRA's ESLint config with typescript-eslint-parser. TSLint could potentially be removed if we take this approach, though it could still be used manually with Benefits
|
Here's my attempt using CRA's ESLint config with TypeScript ESLint Parser: Replace TSLint with CRA's ESLint config |
@nickmccurdy this is a fairly significant change for this project. All your points make sense and are totally valid, but i think we should carefully consider how we would plan to support all the existing CRA-TS projects if we made this change. |
My pull request disables TSLint but will not error if a config still
exists. Do you want full back compatability for existing configs? If so we
could keep TSLint enabled when the config is present and avoid generating
it in new projects. Otherwise we can provide a warning when a config
exists, recommending users run `tslint --project .` manually.
Either way I think we should make the presence of the more relaxed and
consistent config the default for new projects and make it obvious that it
exists for existing users.
…On Mon, Jul 2, 2018, 9:09 PM Ian Schmitz ***@***.***> wrote:
@nickmccurdy <https://github.com/nickmccurdy> this is a fairly
significant change for this project. All your points make sense and are
totally valid, but i think we should carefully consider how we would plan
to support all the existing CRA-TS projects if we made this change.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#333 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA4l9C-ON7JIgcCYCsh4W8I8-Ve5S1KTks5uCsREgaJpZM4UU1o5>
.
|
@gaearon I think the critical issue in the tweet you linked is
Similarly, from another tweet:
The problem is people are having an experience of linting/typechecking that the TypeScript compiler itself is designed to avoid. TypeScript will emit JS just fine so long as your code is syntactically valid; you're free to enable highly opinionated rules like The tool should provide some option that makes it imitate the behavior of |
That's a good point, I think CRA-TS needs a way to allow builds without TS passing. However, I still feel it's best to switch to ESLint for parity with CRA. |
There is an important comment from @nickmccurdy posted on #360:
I can only add that this should be added by default to |
If that's a simple non-breaking change, I think we should do it now. However I'm working on removing TSLint anyway, so that would no longer be an issue if my work is merged. |
Has this stalled? It’s still kind of brutal. https://mobile.twitter.com/monicalent/status/1043780023730221056 |
Awaiting review: #388 Alternatively we may want to recommend existing CRA users to upgrade to CRA 2 for TS |
Agree with @nickmccurdy. Would love to see facebook/create-react-app#4837 make it in, then this fork could be deprecated. |
Is there more to this than changing the default lint severity to "warning" and moving some more strict tsconfig.json options to tsconfig.prod.json? |
FYI, CRA now supports TypeScript: https://github.com/facebook/create-react-app#whats-included |
Note that CRA's TS support hasn't been release yet, but it is merged into their master branch. |
Hi folks!
We currently link to this project from React documentation. I haven’t tried it personally but I assumed it would follow the philosophy in CRA. In particular, we don’t use lint warnings for things that are inconsequential (code style) and only use them to warn people about actual bugs in their code. This was a major design decision after seeing beginners struggle with screens fully of linter errors about spacing and alphabetising props when they’re just learning a library!
However, I recently realized this project doesn’t actually subscribe to this philosophy, and has very strict lint rules:
https://twitter.com/ryanflorence/status/1002028375903354881
https://twitter.com/acemarke/status/1002029156492771328
I don’t want to debate usefulness of this, but I’m wondering how intentional it was. If it is intentional I think we’ll need to avoid recommending this setup for beginners, for the same reason we don’t recommend Airbnb config to them. But maybe it’s not that important and you can consider relaxing them to stay closer to CRA’s original vision?
Thanks for consideration.
The text was updated successfully, but these errors were encountered: