Code Monkey home page Code Monkey logo

eslint-plugin-tss-unused-classes's Introduction

Detect unused tss-react classes

This eslint plugin lets you detect unused tss-react classes:

Screen.Recording.2022-05-07.at.02.49.55.mov

Usage

  1. Add the dependency:
yarn add --dev eslint-plugin-tss-unused-classes
  1. Enable it in you ESLint config

Case 1: You are in a create-react-app project:
Edit your package.json:

{
  //...
  "eslintConfig": {
    "plugins": [
      //...
      "tss-unused-classes"
    ],
    "rules": {
      "tss-unused-classes/unused-classes": "warn"
    }
  },
  //...
}

Example projet

Case 2: You have installed ESLint manually:
Edit your .eslintrc.js file:

module.exports = {
  // ...
  plugins: [
    // ...
    'tss-unused-classes'
  ],
  rules: {
    // ...
    'tss-unused-classes/unused-classes': 'warn'
  }
}

Example project

Disabling warnings

In case of false positive, disabling the warning:

  • For a line: // eslint-disable-next-line tss-unused-classes/unused-classes
  • For the entire file: // eslint-disable-next-line tss-unused-classes/unused-classes

eslint-plugin-tss-unused-classes's People

Contributors

garronej avatar jens-ox avatar sjdemartini avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carsonf benbynum

eslint-plugin-tss-unused-classes's Issues

Rule only works if styles are defined in the same file

This seems like a nice linting rule, however, it is also good practice to split the styles in a separate file. In this case the rule warns that all classes are unused. Is it possible to adjust this rule so that it also works if the styles are defined in a separate file?

Related to the same question at jens-ox#3

Build Error

I get this error every time I do yarn build. When I run yarn start, the first time there is an error, the next time everything is ok

Снимок экрана 2022-11-15 в 16 26 51

  • package.json
{
  "devDependencies": {
    "eslint": "7.32.0",
    "eslint-plugin-tss-unused-classes": "0.0.4"
  }
}
  • eslint.json
{
  "extends": ["custom-plugin"],
  "plugins": ["tss-unused-classes"],
  "settings": {
    "react": {
      "version": "17.0.2"
    }
  },
  "rules": {
    "no-param-reassign": ["error", { "props": false }],
    "react-hooks/exhaustive-deps": "off",
    "no-console": "warn",
    "@typescript-eslint/no-unused-vars": [
      "error",
      { "varsIgnorePattern": "React" }
    ],

    "tss-unused-classes/unused-classes": 2
  },
}

Support Eslint 8

It's working fine for me with eslint v8, but I'm getting a peer dependency warning. Can you update supported version to include v8?

Doesn't work if classes are destructured

Background

Our team has just migrated to MUI5 and chosen to use tss-react/mui because the migration was much simpler coming from MUI4. A lot of our MUI 4 based code looked like this:

const { root, label } = useStyles({});

To make the migration simpler and avoid having to re-write many extra lines of code, we simply destructured the classes from tss-react/mui's makeStyles, like so:

const { classes: { root, label } } = useStyles();

Issue

This plugin only seems to work when using classes.classname directly.

Using destructuring:
image
results in a false positive:
image

But everything works fine if we use classes.root. Is it possible to make this plugin work with destructuring? Our team would love to use it, but currently it's not feasible due to the large number of lines we'd need to re-write.

Thanks for all your hard work, we're really enjoying tss-react/mui!

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.