• Stars
    star
    577
  • Rank 77,134 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created over 2 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reduce Similar & Duplicated CSS Classes with Diff in Seconds!

CSS-CHECKER

CSS Checker - Less is More

中文文档

Purpose

css-checker checks your CSS styles for duplications and finds the diff among CSS classes with high similarity in seconds. It is designed to avoid redundantly or similar css and styled components between files and to work well for both local developments, and for automation like CI.

Similarity check, duplication check, colors check, long lines warning are supported by default. Styled components check, Unused CSS check can be enabled optionally. CSS checker can help reduce CSS code for developers in seconds.

See more on Wiki

Install

Using Go:

go install github.com/ruilisi/css-checker@latest

(With go version before 1.17, use go get github.com/ruilisi/css-checker). Or download from releases

Using npm:

npm install -g css-checker-kit

Usage

Run

  • cd PROJECT_WITH_CSS_FILES and just run:
css-checker
  • (Beta Feature: styled components check): css-checker -styled

DEMO

(Check and show the diff among similar classes (>=80%). Colors, long scripts that are used more than once will also be pointed out by default. Check css-checker -help for customized options.)

  • Colors with rgb/rgba/hsl/hsla/hex will be converted to rbga and compared together.

  • (Alpha Feature: Find classes that are not referred to by your code): css-checker -unused

Run with path

  • css-checker -path=YOUR_PROJECT_PATH

File Ignores

  • CSS-Checker ignores paths in .gitignore by default (You can disable this to read all files by using -unrestricted=true).
  • For adding extra paths to ignore, using: -ignores=node_modules,packages .

Config File

  • css-checker.yaml: CSS-Checker read this yaml file in your project path for settings, you can use parameters in Basic Commands sections to set up this file (without the leading '-').
  • A sample yaml file named 'css-checker.example.yaml' is also provided in this project, move it to your project path with the name 'css-checker.yaml' and it will work.
  • To specify your config file, use -config=YOUR_CONFIG_FILE_PATH.

Advanced Features

  • Run with styled components check only (without checks for css): css-checker -css=false -styled
  • Find classes that not referred by your code: css-checker -unused (Alpha)

Basic commands

  • colors: whether to check colors (default true)
  • css: whether to check css files (default true as you expected)
  • config: set configuration file path (string, default './css-checker.yaml')
  • ignores: paths and files to be ignored (e.g. node_modules,*.example.css) (string, default '')
  • length-threshold: Min length of a single style value (no including the key) that to be considered as long script line (default 20)
  • long-line: whether to check duplicated long script lines (default true)
  • path: set path to files, default to be current folder (default ".")
  • sections: whether to check css class duplications (default true)
  • sim: whether to check similar css classes (default true)
  • sim-threshold: Threshold for Similarity Check ($\geq20$ && $\lt100$) (int only, e.g. 80 for 80%, checks for identical classes defined in sections) (default 80)
  • styled: checks for styled components (default false)
  • unrestricted: search all files (gitignore)
  • unused: whether to check unused classes (Beta)
  • version: prints current version and exits
  • to-file: wherther generate a html file (default true)
  • file-name: if to-file is true, set the html file name(default css-checker.html)

Outputs:

image.png

How to get similarities between classes?

  1. Hash each line of class (aka. section in our code), Generate map: LineHash -> Section.
  2. Convert map LineHash -> Section => [SectionIndex1][SectionIndex2] -> Duplicated Hashes, section stands for css class.
  3. In map: [SectionIndex1][SectionIndex2] -> Duplicated Hashes, number of the duplicated hashes stands for duplicated lines between classes.

Similarity Check

Check similarities ($\geq(sim-threshold)$ && $\lt100$) between classes. This will print the same line in between classes.

  • $sim-threshold$: using -sim-threshold= params or setting sim-threshold: in config yaml file, default 80, min 20.

image.png

Duplicated CSS Classes

Similar to Similarity Check but put those classes that are totally identical to each other.

Long Script Line Check

Long scripts can be saved as variables to make your life easier. This will only alert when long lines are used for more than once.

image.png

Colors Check

Check colors in HEX/RGB/RGBA/HSL/HSLA that are used more than once in your code. As for supporting of different themes and possibly future updates of your color set, you may consider putting them as CSS variables.

image.png

Build & Release

  • make test-models
  • make build
  • make release

Q&A

Ugly output in PowerShell

From PowerShell, paste the following script and run it to activate ANSI escape sequences, then restart your PowerShell.

Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1

Authors

  • Xiemala Team. It helps in removing hundreds of similar CSS classes for developers in this project.

More Repositories

1

fortune-sheet

A drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets
TypeScript
2,384
star
2

rails-pangu

Rails starter kit that every startup needs
Ruby
192
star
3

react-chessground

React wrapper of Chessground
JavaScript
131
star
4

go-pangu

rest api web server based on go(High availability, high security, high performance)
Go
45
star
5

react-media-previewer

A media previewer component for React
TypeScript
20
star
6

NSHoverableButton

NSButton with two images for hovering and not hovering separately
Swift
19
star
7

react-keycode-input

A cool component for inputing many kinds of code
JavaScript
17
star
8

macbit

Macbit aims to solve mac development issues in a bit level.
C
11
star
9

chart-pangu

Pangu-chart is a helm chart template which inherits from the default template, but brings many conveniences originated from our daily devops.
HTML
10
star
10

rails-influxdb-logger

Logger for Influxdb in Rails
Ruby
10
star
11

NSGradientView

NSView with Gradient Background Colour Settings for Mac OS
Swift
9
star
12

feishu-api

FeishuApi is an integration of commonly used feishu open platform's APIs, easy to call.
Ruby
7
star
13

dockery

JavaScript
7
star
14

CountryCodeNSTextField

CountryCodeNSTextField subclasses NSTextfield for International Phone Calling Code Input With Flags
Swift
6
star
15

weibo-crawler

Weibo-crawler is a crawler project based on golang colly framework to crawl weibo sites and get information. It crawls web content by regular expressions and Xpath selector, spatially transforms keywords using word vector model, and clusters text content by HDBSCAN clustering algorithm.
Go
6
star
16

pangu.js

JavaScript
5
star
17

golang-crawler-example

HTML
5
star
18

learn-webpack

JavaScript
5
star
19

goetc

Go
5
star
20

Rocket.Chat.Go.SDK

Go SDK for REST API and Realtime api(almost all api)
Go
5
star
21

NSScrollSideBar

Swift
4
star
22

react-pangu

JavaScript
4
star
23

nextjs-docker-base

docker image base for nextjs
Dockerfile
4
star
24

css-cookbook

https://ruilisi.github.io/css-cookbook/
4
star
25

govet

Go
4
star
26

actioncable-jwt

Actioncable with authentication by jwt token
Ruby
3
star
27

golang-examples

Go
3
star
28

IMChatSDK-Mac

Swift
2
star
29

fortune-sheet-demo

HTML
2
star
30

UICustomView

Swift
2
star
31

IMChatSDK

Swift
2
star
32

xcode-cookbook

2
star
33

actioncable-rails

JavaScript
1
star
34

esheep

1
star
35

react-chessground-demo

JavaScript
1
star
36

rails-6-api-template

Ruby
1
star
37

rollup-react-library

Another react library creator which follows latest js libraries
JavaScript
1
star
38

chatsdk

Sample DatoCMS website built with GatsbyJS
Sass
1
star
39

fortune-sheet-docs

HTML
1
star