LogoLogo
HomeGitHubPlayground
v4
v4
  • ๐Ÿ”งSetup
  • ๐Ÿ”API References
    • tss - the Modern API
    • keyframes
    • <GlobalStyles />
    • makeStyles -> useStyles
    • withStyles
  • โšกSSR
    • Next.js
    • Gatsby
    • Other backends
  • ๐ŸŽฏIncrease specificity
  • ๐Ÿฆฑclasses overrides
  • ๐ŸงนDetecting unused classes
  • ๐Ÿ’ฝEmotion Cache
  • ๐Ÿ’ซNested selectors (ex $ syntax)
  • ๐ŸญMUI Global styleOverrides
  • ๐Ÿ“ฆPublish a module that uses TSS
  • ๐ŸฉณMUI sx syntax
  • ๐Ÿ“ฒReact Native
  • ๐Ÿ†˜Fix broken styles after upgrading to MUI v5 with TSS
  • โฌ†๏ธMigration v3 -> v4
Powered by GitBook
On this page
  • Usage
  • Disabling warnings

Was this helpful?

Edit on GitHub

Detecting unused classes

Previousclasses overridesNextEmotion Cache

Last updated 8 months ago

Was this helpful?

There is that detects unused classes for makeStyles and the Modern API:

Usage

  1. Add the dependency:

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

Case 1: You have installed ESLint manually: Edit your eslint.config.js file:

eslint.config.js
import tssUnusedClasses from 'eslint-plugin-tss-unused-classes'

export default tseslint.config(
  { ignores: ['dist'] },
  {
    plugins: {
      // ...
      'tss-unused-classes': tssUnusedClasses,
    },
    rules: {
      // ...
      'tss-unused-classes/unused-classes': 'warn',
    },
  },
)
package.json
{
  //...
  "eslintConfig": {
    "plugins": [
      //...
      "tss-unused-classes"
    ],
    "rules": {
      "tss-unused-classes/unused-classes": "warn"
    }
  },
  //...
}

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

Case 2: You are (still) in a project: Edit your package.json:

๐Ÿงน
Example project
create-react-app
Example projet
an ESLint plugin