Giter Site home page Giter Site logo

maleksandrov / css-checker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ruilisi/css-checker

0.0 1.0 0.0 105 KB

Show Similar & Duplicated CSS Scripts with Diff in Seconds!

License: MIT License

Go 94.05% Makefile 1.06% CSS 4.39% Shell 0.26% JavaScript 0.24%

css-checker's Introduction

CSS-CHECKER

Css Checker - Less is More

中文文档

Purpose

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

Colors check, long scripts, unused CSS classes warning of css are also supported by default. This project is provided by Xiemala Team, it helps in remove hundreds of similar css classes for developers in this project.

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
  • (Alpha Feature: Find classes that not referred by your js/jsx/ts/tsx/html code): css-checker -unused

DEMO

(Check and show the diff among similar classes (>=80%). Colors, long scripts that used more then 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.

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 providied 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.

Basic commands

  • colors: whether to check colors (default true)
  • 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)
  • unrestricted: search all files (gitignore)
  • unused: whether to check unused classes (Beta)
  • version: prints current version and exits

Outputs:

image.png

How we 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 total identical to each other.

Long Script Line Check

Long scripts can be saved as varirables to make your life easiler. This will only alert when long scriptes are used for more then once.

image.png

Colors Check

Check colors in HEX/RGB/RGBA/HSL/HSLA that used more then once in your code. As for supporting of diffrent themes and possible future updates of you color set, you may consider to put them as css variables.

image.png

Build & Release

  • make test-models
  • make build
  • make release

css-checker's People

Contributors

hophacker avatar m1natott avatar zhcalvin avatar

Watchers

 avatar

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.