2.12.0 • Published 2 years ago

eslint-plugin-css-modules v2.12.0

Weekly downloads
59,077
License
MIT
Repository
github
Last release
2 years ago

eslint-plugin-css-modules

Build Status

This plugin intends to help you in tracking down problems when you are using css-modules. It tells if you are using a non-existent css/scss/less class in js or if you forgot to use some classes which you declared in css/scss/less.

Rules

  • css-modules/no-unused-class: You must use all the classes defined in css/scss/less file.

If you still want to mark a class as used, then use this comment on top of your file

/* eslint css-modules/no-unused-class: [2, { markAsUsed: ['container'] }] */

where container is the css class that you want to mark as used. Add all such classes in the array.

If you use the camelCase option of css-loader, you must also enabled it for this plugin

/* eslint css-modules/no-unused-class: [2, { camelCase: true }] */
  • css-modules/no-undef-class: You must not use a non existing class, or a property that hasn't been exported using the :export keyword.

If you use the camelCase option of css-loader, you must also enabled it for this plugin

/* eslint css-modules/no-undef-class: [2, { camelCase: true }] */

Installation

npm i --save-dev eslint-plugin-css-modules

Usage:

.eslintrc

{
  "plugins": [
    "css-modules"
  ],
  "extends": [
    "plugin:css-modules/recommended"
  ]
}

You may also tweak the rules individually. For instance, if you use the camelCase option of webpack's css-loader:

{
  "plugins": [
    "css-modules"
  ],
  "extends": [
    "plugin:css-modules/recommended"
  ],
  "rules": {
    "css-modules/no-unused-class": [2, { "camelCase": true }],
    "css-modules/no-undef-class": [2, { "camelCase": true }]
  }
}

The camelCase option has 4 possible values, see css-loader#camelCase for description:

true | "dashes" | "only" | "dashes-only"

Specifying base path

You can specify path for the base directory via plugin settings in .eslintrc. This is used by the plugin to resolve absolute (S)CSS paths:

{
  "settings": {
    "css-modules": {
      "basePath": "app/scripts/..."
    }
  }
}

Screen Shot

ScreenShot

   1:8   error  Unused classes found: container  css-modules/no-unused-class
   5:17  error  Class 'containr' not found       css-modules/no-undef-class
  10:26  error  Class 'foo' not found            css-modules/no-undef-class

scss:

/* .head is global, will not be used in js */
:global(.head) {
  color: green;
}

.container {
  width: 116px;

  i {
    font-size: 2.2rem;
  }

  .button {
    padding: 7px 0 0 5px;
  }
}

.footer {
  color: cyan;
}
eslint-config-bigpopakap@wildberries/boilerplate-eslint-config@qcolate/eslint-config-react@alfabank/eslint-config-site@teachers/eslint-config-tpt-typescript@infinitebrahmanuniverse/nolb-eslint-plugin-c@everything-registry/sub-chunk-1610wheelhouse-linter@divvy-homes/eslint-config-divvyhomes@cyco130/eslint-config@coorpacademy/eslint-plugin-coorpacademy@byandu/eslint-config-beta@appfollow/eslint-config@april9/eslint-config-custom@akh-test/eslint-config@alex-e-leon/eslint-config@alexandragr-ssr-micro/eslint-react@bignumbers/eslint-config@bigpopakap/eslint-config@digigov/cli-lint@digigov/dev@digest/eslint-config-react@samelogic/eslint-config@newsteam/eslint@newsteam/eslint-config@mygento/eslint-config@eyesee/eslint-config@mikey-pro/eslint-config@mikey-pro/eslint-config-mkt@mikey-pro/eslint-config-preact@ineedj/eslintrc@rakkasjs/eslint-config@rakkasjs/eslint-config-js@siteone/eslint-configreadable-code@walid-mokrani/react-scripts@wasc/tools@wildberries/eslint-config@wildberries/eslint-config-root@tiwariav/eslint-config@tools-aoeur/eslint-config@volue/eslint-config@stimul/eslint-config-react@stimul/eslint-confign-react@stimul/eslint-react@stefanoa1/eslint-plugin-sab@sweetlikepete/eslint@tamland/eslint@zohodesk/react-clicefc-toolsdbz-flame-scriptsdevtools-for-reacteslint-plugin-easemob-kefuspaeslint-config-leneslint-config-krosseslint-config-pandolaeslint-config-pavoeslint-config-readableeslint-config-veaudryeslint-config-videoamp-reacteslint-config-yaruseslint-config-unioneslint-config-skueslint-config-cnpeslint-config-chac-commoneslint-config-current-thingeslint-config-homezeneslint-config-ivaneslint-config-gmanaeslint-config-molindoeslint-plugin-nkaeslint-plugin-packflt
2.12.0

2 years ago

2.11.1

2 years ago

2.11.4

2 years ago

2.11.2

2 years ago

2.11.3

2 years ago

2.11.0

6 years ago

2.10.0

7 years ago

2.9.1

7 years ago

2.9.0

7 years ago

2.8.1

7 years ago

2.8.0

7 years ago

2.7.5

8 years ago

2.7.4

8 years ago

2.7.3

8 years ago

2.7.2

8 years ago

2.7.1

8 years ago

2.6.1

8 years ago

2.6.0

8 years ago

2.5.0

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.0

8 years ago

2.0.0

9 years ago

1.0.10

9 years ago

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago