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

Add support for TSLint #5697

Closed
wants to merge 10 commits into from
Closed

Add support for TSLint #5697

wants to merge 10 commits into from

Conversation

ianschmitz
Copy link
Contributor

@ianschmitz ianschmitz commented Nov 3, 2018

Closes #5641.

Adds support for TSLint via fork-ts-checker-webpack-plugin.

TODO:

@@ -9,4 +9,5 @@ ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
// tslint:disable-next-line:no-floating-promises
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Timer let me know how you feel about this. I refactored all the serviceWorker code to use async/await, which fixes all the TSLint errors.

@ianschmitz ianschmitz changed the title Tslint Add support for TSLint Nov 3, 2018
@@ -0,0 +1,42 @@
{
"defaultSeverity": "warning",
"rulesDirectory": "tslint-microsoft-contrib",

Choose a reason for hiding this comment

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

tslint-config-prettier and tslint-react would be nice defaults to have 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andyrichardson which rules were you thinking from tslint-react? A lot of the rules seemed to be style prefer nces which we try to avoid.

Choose a reason for hiding this comment

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

Fair point - jsx-key is already flagged by React so I guess the only other useful non-style option is jsx-self-close.

Copy link

@mohamedmansour mohamedmansour Nov 6, 2018

Choose a reason for hiding this comment

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

This will expose tslint.json to the root, so technically we can add our own rules to the project, correct? The current way create-react-app does eslint, it exposes a package.json config called eslintConfig, we could do the same and name it tslintConfig.

Copy link
Contributor

@Timer Timer Nov 6, 2018

Choose a reason for hiding this comment

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

@mohamedmansour just like ESLint, you will not be able to add your own rules. Added rules will strictly affect the editor output, not the build tools.

If you need to check linting on commit, I suggest you use a precommit hook.

Copy link

@mohamedmansour mohamedmansour Nov 6, 2018

Choose a reason for hiding this comment

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

This is unfortunate, why couldn't we change that model and allow the users to override tslint.json? The beautiful thing about TypeScript is that it is a superset of JavaScript, each team can decide what kind of strictness they need or want. Once create-react-app enforce this projects strictness for linting, then I cannot use the rules that I want to enforce in my own project.

For example, we are overriding many rules to fit our teams standard here https://github.com/OfficeDev/office-ui-fabric-react/blob/master/packages/tslint-rules/tslint.json

And in my current project, I just do the following in tslint.json:

{
  "extends": [
    "@uifabric/tslint-rules"
  ],
  "rules": {
    "jsx-no-lambda": false,
    "jsx-ban-props": false,
    "typedef": [false]
  }
}

Having a choice on how linting works is more preferable than the way this PR does it.

@samuelcastro
Copy link

samuelcastro commented Nov 9, 2018

@ianschmitz What's left to get this done? How can we help?

@ianschmitz
Copy link
Contributor Author

@ianschmitz What's left to get this done? How can we help?

This would be awesome: palantir/tslint-react#186

@adriankremer
Copy link

adriankremer commented Dec 5, 2018

it's nice that someone already works on this!!!

Today i also thought about mapping eslint to tslint ( tslint-eslint-rules ) or parsing typescript with eslint typescript-eslint-parser
which both would let us stay on one linting ruleset and also would have the advantages of keeping the linting configuration detached from the app.

Unfortunately mapping eslint to tslint does not work with "extends" so we would have to create another project (e.g. tslint-config-react-app) and duplicate the ruleset. And my favourite: parsing typescript with eslint does not work on the IDE because of the fileextension.

@adriankremer
Copy link

btw. will this PR cover IDE support?

@ianschmitz
Copy link
Contributor Author

We should be able to follow the same pattern that we already have for ESLint to add a dummy tslint.json file to root of repo and extend our ruleset

@adriankremer
Copy link

adriankremer commented Dec 5, 2018

yes thats the only way i think (too bad there is no tslintConfig standard for package.json). then it would be the best to create another package like tslint-config-react-app and reference this via fork-ts-checker-webpack-plugin and the tslint.json ?

@Timer already reserved it on npm :) https://www.npmjs.com/package/tslint-config-react-app

@ianschmitz
Copy link
Contributor Author

Yep we have that in this PR already 🙂

@harrysolovay
Copy link

I created a solution to this problem. You can use your own TSLint instead of the built-in linting or fork-ts-checker by using the Rescripts framework and its use-tslint-config rescript (I just released it and would really love your feedback!) :)

@samuelcastro
Copy link

@harrysolovay Rescripts seems amazing, looking forward to test it, good job!

@harrysolovay
Copy link

@samuelcastro thank you so much! Please let me know your thoughts & any suggestions :)

@ianschmitz
Copy link
Contributor Author

Based on the current roadmap that has been laid out over at microsoft/TypeScript#29288, it sounds like they will be standardizing on ESLint:

our editor team will be focusing on leveraging ESLint rather than duplicating work. For scenarios that ESLint currently doesn't cover (e.g. semantic linting or program-wide linting), we'll be working on sending contributions to bring ESLint's TypeScript support to parity with TSLint. As an initial testbed of how this works in practice, we'll be switching the TypeScript repository over to using ESLint, and sending any new rules upstream.

I will keep a close eye on this to see if this is the direction that we should follow as they make progress bringing ESLint up to snuff to support TypeScript.

@ianschmitz
Copy link
Contributor Author

More information from ESLint team:

https://eslint.org/blog/2019/01/future-typescript-eslint

@PutziSan PutziSan mentioned this pull request Jan 22, 2019
3 tasks
@ianschmitz ianschmitz removed this from the 3.0 milestone Feb 25, 2019
@ianschmitz
Copy link
Contributor Author

Closing in favor of #6513

@ianschmitz ianschmitz closed this Feb 25, 2019
@lock lock bot locked and limited conversation to collaborators Mar 2, 2019
@ianschmitz ianschmitz deleted the tslint branch June 20, 2020 19:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants