Git Product home page Git Product logo

Comments (2)

aghoneim92 avatar aghoneim92 commented on August 18, 2024

Opened palantir/tslint#4305 in tslint as well

from create-react-app-typescript.

 avatar commented on August 18, 2024

I think your main point about having a relaxed rule-set is great. I'm using CRA as part of a stack for enterprise applications so I have the experience and time to customize the rule-set to our taste. I find it annoying and distracting, but it's worth it to make sure standards are followed throughout a large code base. But, as you point out, that's not the only use-case here, and indeed one of the main selling points of CRA is that it's "low friction" for new comers. So a relaxed rule set would be spot on for that, and better than disabling TSLint all together.

But, what I want to address is a way of using TSLint that helps with:

[...] if you disable the rule you don't like, you have to restart the bundler to see the change in effect..

I've done the following with "normal" CRA, and using VSCode as my IDE. I'm not 100% sure how it'd work with CRA-TS. I suspect it'd work okay, but I've not tried it so there may be hidden pitfalls. This approach should work with any IDE that uses TSC to provide warnings and errors. VSCode, Atom, Sublime, VS2017, etc. And also any build process that uses TSC, so the rules are applied at build time, as well as development time.

TSLint can be loaded as a TypeScript plugin, which will then provide it's warnings and errors as if they were native TSC warnings and errors.

https://github.com/Microsoft/typescript-tslint-plugin

This plugin requires TypeScript 2.4 or later. It can provide intellisense in both JavaScript and TypeScript files within any editors that uses TypeScript to power their language features.

And as part of that, it'll pick up (most) changes to tslint.json as they happen. I have encountered a couple of cases where I've had to bounce the IDE to pick up the change, though that might just have been my impatience and I didn't wait quite long enough for the change to be detected and acted upon, but they were a tiny minority.

e.g.

I'm working on some code in a .ts file and use console.log("foo"); and TSLint points out no-console! Ugh, I'm deving, I want to use the console!

So I switch to tslint.json, and tweak the config with a snippy comment that vaguely explains the "why":

    // Yes console.
    "no-console": false,

And then, when I switch back to the .ts file I was working in, the error disappears within a few seconds and I can carry on. That greatly reduces the annoyance/distraction factor.

And actually that's given me an idea. A VSCode extension that would let someone right click on a peice of code with a warning/error, and choose "disable TSLint rule" from the context menu. It'd modify the tslint.json and I wouldn't even have to leave the original .ts file! Something to investigate on a slow day maybe.

from create-react-app-typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.