is-misused-css

0.0.4 • Public • Published

is-misused-css

Check if CSS properties are correctly applied.

Inspired by DevTools, which offers a helpful tooltip now when CSS properties are set, but don't apply to elements. The source-code is taken from the Chromium DevTools repository, so it will show the exactly same information, just as JavaScript API.

Please note: font-variation-settings is currently not checked and can currently only be checked by the DevTools.

Example:

.a {
	display: block;
	align-items: center; /* <-- won't apply, because of 'display: block' => is misused */
}

DevTools:

DevTools shows an tooltip that suggests using something different than display: block

is-misused-css:

Usage

In the browser:

  • Copy is-misused-css.browser.js
  • Run it in a new DevTools snippet, or use a bookmarklet generator
  • Run [...document.querySelectorAll("*")].forEach(el => console.log(el, isMisusedCSS.scan(el)) in your console

With npm/pnpm/yarn:

npm i is-misused-css

import { scan } from 'is-misused-css';

const hints = scan(document.querySelector('#myelement'))
console.log(hints)

Further Ideas

  • Minifier/Critical CSS extractors: Remove properties that do nothing
  • Stylelint: Add a warning/error when there is a CSS prop that does nothing
  • Eslint for JSX/TSX: Add a warning/error for CSS-in-JS
  • Tailwind / Atomic CSS: Lint when classes are used that do not work together

Readme

Keywords

none

Package Sidebar

Install

npm i is-misused-css

Weekly Downloads

1

Version

0.0.4

License

none

Unpacked Size

2.54 MB

Total Files

38

Last publish

Collaborators

  • kurtextrem