Skip to content

Commit dcaa279

Browse files
committed
Initial commit
0 parents  commit dcaa279

File tree

6 files changed

+869
-0
lines changed

6 files changed

+869
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test/
2+
.DS_Store

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Cask

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(source gnu)
2+
(source melpa)
3+
4+
(package-file "flycheck-css-colorguard.el")

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# flycheck-css-colorguard
2+
3+
[![License GPL 3][https://img.shields.io/badge/license-GPL_3-green.svg?dummy]][https://github.com/simplify/flycheck-css-colorguard/blob/master/COPYING]
4+
5+
This is extension for [Flycheck][http://www.flycheck.org/].
6+
It uses [CSS Colorguard][https://github.com/SlexAxton/css-colorguard] and
7+
warns you when colors you've added are too similar to ones that already exist
8+
in your css file.
9+
10+
*Use CSS Colorguard 1.0.0 or higher!*
11+
12+
![flycheck-irony screenshot](screenshot-flycheck-css-colorguard.png)
13+
14+
## Instalation
15+
16+
Package in available on [Melpa][https://melpa.org/].
17+
18+
### [Cask][http://cask.readthedocs.org]
19+
20+
```cl
21+
(source gnu)
22+
(source melpa)
23+
24+
(depends-on "flycheck-css-colorguard")
25+
```
26+
27+
### `init.el`
28+
29+
```cl
30+
(eval-after-load 'flycheck
31+
'(progn
32+
(require 'flycheck-css-colorguard)
33+
(flycheck-add-next-checker 'css-csslint
34+
'css-colorguard 'append)))
35+
```
36+
37+
## Usage
38+
39+
Just open any css file. If flycheck is properly configured, flycheck-css-colorguard will start automatically.
40+
41+
## License
42+
43+
This program is free software: you can redistribute it and/or modify it under
44+
the terms of the GNU General Public License as published by the Free Software
45+
Foundation, either version 3 of the License, or (at your option) any later
46+
version.
47+
48+
This program is distributed in the hope that it will be useful, but WITHOUT ANY
49+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
50+
PARTICULAR PURPOSE. See the GNU General Public License for more details.
51+
52+
You should have received a copy of the GNU General Public License along with
53+
this program. If not, see http://www.gnu.org/licenses/.

flycheck-css-colorguard.el

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
;;; flycheck-css-colorguard.el --- Detect similar colors in CSS
2+
3+
;; Copyright (C) 2015 Saša Jovanić
4+
5+
;; Author: Saša Jovanić <[email protected]>
6+
;; URL: https://github.com/simplify/flycheck-css-colorguard/
7+
;; Version: 0.1.0
8+
;; Keywords: flycheck, CSS
9+
;; Package-Requires: ((flycheck "0.22") (emacs "24.4"))
10+
11+
;; This file is not part of GNU Emacs.
12+
13+
;; This program is free software: you can redistribute it and/or modify
14+
;; it under the terms of the GNU General Public License as published by
15+
;; the Free Software Foundation, either version 3 of the License, or
16+
;; (at your option) any later version.
17+
18+
;; This program is distributed in the hope that it will be useful,
19+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
;; GNU General Public License for more details.
22+
23+
;; You should have received a copy of the GNU General Public License
24+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
26+
27+
;;; Commentary:
28+
29+
;; This is extension for Flycheck.
30+
31+
;; From https://github.com/SlexAxton/css-colorguard:
32+
;; CSS Colorguard helps you maintain the color set that you want, and warns
33+
;; you when colors you've added are too similar to ones that already exist.
34+
35+
;; For more infomations about CSS Colorguard, please check the GitHub
36+
;; https://github.com/SlexAxton/css-colorguard
37+
38+
;; For more information about Flycheck:
39+
;; http://www.flycheck.org/
40+
;; https://github.com/flycheck/flycheck
41+
42+
;; For more information about this Flycheck extension:
43+
;; https://github.com/simplify/flycheck-css-colorguard
44+
45+
46+
;;;; Setup
47+
48+
;; (eval-after-load 'flycheck
49+
;; '(progn
50+
;; (require 'flycheck-css-colorguard)
51+
;; (flycheck-add-next-checker 'css-csslint
52+
;; 'css-colorguard 'append)))
53+
54+
55+
;;;; CSS Colorguard output 1.0.0 or higher:
56+
;; line 2 col 3 #020202 collides with rgba(0,0,0,1) (2:44)
57+
;; line 3 col 3 #000000 collides with rgba(0,0,0,1) (2:44)
58+
;; line 3 col 3 #000000 collides with #020202 (2:59)
59+
;; line 7 col 3 black collides with rgba(0,0,0,1) (2:44)
60+
;; line 7 col 3 black collides with #020202 (2:59)
61+
;; line 12 col 3 rgb(0,0,0) collides with rgba(0,0,0,1) (2:44)
62+
;; line 12 col 3 rgb(0,0,0) collides with #020202 (2:59)
63+
;; line 13 col 3 rgba(0,0,0,1) collides with #020202 (2:59)
64+
;; line 16 col 3 hsl(0,0%,0%) collides with rgba(0,0,0,1) (2:44)
65+
;; line 16 col 3 hsl(0,0%,0%) collides with #020202 (2:59)
66+
;; line 17 col 3 hsla(0,0%,0%,1) collides with rgba(0,0,0,1) (2:44)
67+
;; line 17 col 3 hsla(0,0%,0%,1) collides with #020202 (2:59)
68+
;; line 20 col 3 #010101 collides with rgba(0,0,0,1) (2:44)
69+
;; line 20 col 3 #010101 collides with #020202 (2:59)
70+
;; line 52 col 5 #000000 collides with rgba(0,0,0,1) (2:44)
71+
;; line 52 col 5 #000000 collides with #020202 (2:59)
72+
;; line 52 col 5 #000000 collides with #010101 (20:20)
73+
74+
;;;; CSS Colorguard output before 1.0.0:
75+
;; Collision: #000000, #020202
76+
;; - rgba(0,0,0,1) (#000000) [line: 2, 3, 7, 12, 13, 16, 17, 52] is too close (0.3146196209793196) to #020202 (#020202) [line: 2]
77+
;; Collision: #000000, #010101
78+
;; - rgba(0,0,0,1) (#000000) [line: 2, 3, 7, 12, 13, 16, 17, 52] is too close (0.15712369811016996) to #010101 (#010101) [line: 20]
79+
;; Collision: #020202, #010101
80+
;; - #020202 (#020202) [line: 2] is too close (0.1574963682909058) to #010101 (#010101) [line: 20]
81+
82+
83+
;;; Code:
84+
85+
(require 'flycheck)
86+
87+
;;;; For output before css-colorguard 1.0.0
88+
;; (defun flycheck-parse-css-colorguard (output checker buffer)
89+
;; "Proces OUTPUT from colorguard into flycheck errors.
90+
;; CHECKER and BUFFER are returned with flycheck error."
91+
;; (let (errors)
92+
;; (dolist (line (delete "" (split-string output "Collision: ")))
93+
;; (let ((good-part (nth 1 (split-string line " - "))))
94+
;; (let ((first-color (car (split-string good-part " \\[Line: ")))
95+
;; (second-color (car (split-string (nth 1 (split-string good-part " to ")) " \\[Line: ")))
96+
;; (line-numbers (car (split-string (nth 1 (split-string good-part " \\[Line: ")) "]")))
97+
;; (second-line (car (split-string (nth 2 (split-string good-part " \\[Line: ")) "]")))
98+
;; (collision (car (split-string (nth 1 (split-string good-part "]")) " to ")))
99+
;; )
100+
;; (dolist (error-line (split-string line-numbers ", "))
101+
;; (push (flycheck-error-new-at
102+
;; (flycheck-string-to-number-safe error-line)
103+
;; nil
104+
;; 'info
105+
;; (format "%s is too close to %s at line %s" first-color second-color second-line)
106+
;; :checker checker
107+
;; :buffer buffer)
108+
;; errors)
109+
;; (push (flycheck-error-new-at
110+
;; (flycheck-string-to-number-safe second-line)
111+
;; nil
112+
;; 'info
113+
;; (format "%s is too close to %s at line %s" second-color first-color error-line)
114+
;; :checker checker
115+
;; :buffer buffer)
116+
;; errors)))))
117+
;; (nreverse errors)))
118+
119+
(flycheck-define-checker css-colorguard
120+
"Detect similar colors in CSS using CSS Colorguard.
121+
122+
See URL
123+
`https://github.com/SlexAxton/css-colorguard'."
124+
:command ("colorguard" "--file" source)
125+
;;(option "--threshold" "3")
126+
;; :error-parser flycheck-parse-css-colorguard ;; For css-colorguard older then 1.0.0
127+
:error-patterns
128+
((warning line-start
129+
" line " line (one-or-more " ") " col " column (one-or-more " ") (message) line-end))
130+
:modes (css-mode))
131+
132+
(add-to-list 'flycheck-checkers 'css-colorguard 'append)
133+
134+
(provide 'flycheck-css-colorguard)
135+
136+
;;; flycheck-css-colorguard.el ends here
123 KB
Loading

0 commit comments

Comments
 (0)