pronto-stylelint 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/lib/pronto/stylelint/config.rb +44 -0
- data/lib/pronto/stylelint/linter.rb +72 -0
- data/lib/pronto/stylelint/version.rb +3 -1
- data/lib/pronto/stylelint.rb +27 -59
- metadata +5 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72aadfab27603a70d2693342dd21de34d2029d2dde321ff65813375f6d2ff06d
|
4
|
+
data.tar.gz: 965e9c5d044b55e4895812025d4482f63b1db1d71e7e51db2f6cc56cbbaadfaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62ea066e712ea0c8632b2d9502481e6c9e2dc11e23b72f4a2e4e9c01e803fa87b92d27e3fe83731613f2597ae301f035b3f1e2420008987b4c0b50d697a91652
|
7
|
+
data.tar.gz: fe4cac1fc9d5a28963fac3739141797f7b01ad9a3d757ae816c29972f74b53624bd2e2fb5ad3c4d11a98c933647648e3e5e9533e37b659a1403a1230aa5f5a44
|
data/README.md
CHANGED
@@ -7,13 +7,13 @@
|
|
7
7
|
|
8
8
|
Pronto runner for [stylelint](http://stylelint.io), the mighty, modern CSS linter. [What is Pronto?](https://github.com/prontolabs/pronto)
|
9
9
|
|
10
|
-
Uses official stylelint executable installed by `npm`.
|
10
|
+
Uses the official stylelint executable installed by `npm`.
|
11
11
|
|
12
12
|
Heavily inspired by [doits/pronto-eslint_npm](https://github.com/doits/pronto-eslint_npm).
|
13
13
|
|
14
14
|
## Prerequisites
|
15
15
|
|
16
|
-
You'll need to install [stylelint by yourself with npm](http://stylelint.io/user-guide/cli/). If `stylelint` is in your `PATH`, everything will simply work, otherwise you have to provide pronto-stylelint your custom executable path (see [below](#configuration-of-stylelint)).
|
16
|
+
You'll need to install [stylelint by yourself with npm](http://stylelint.io/user-guide/cli/). If `stylelint` is in your `PATH`, everything will simply work, otherwise, you have to provide pronto-stylelint your custom executable path (see [below](#configuration-of-stylelint)).
|
17
17
|
|
18
18
|
## Configuration of stylelint
|
19
19
|
|
@@ -21,9 +21,9 @@ Configuring stylelint via [.stylelintrc and consorts](http://stylelint.io/user-g
|
|
21
21
|
|
22
22
|
## Configuration of pronto-stylelint
|
23
23
|
|
24
|
-
pronto-stylelint can be configured by
|
24
|
+
pronto-stylelint can be configured by adding to the [pronto configuration file](https://github.com/prontolabs/pronto?tab=readme-ov-file#configuration) `.pronto.yml`.
|
25
25
|
|
26
|
-
|
26
|
+
The following options are available:
|
27
27
|
|
28
28
|
| Option | Meaning | Default |
|
29
29
|
| -------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------- |
|
@@ -34,8 +34,9 @@ Following options are available:
|
|
34
34
|
Example configuration to call custom stylelint executable and specify custom options:
|
35
35
|
|
36
36
|
```yaml
|
37
|
-
# .
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
# .pronto.yml
|
38
|
+
stylelint:
|
39
|
+
stylelint_executable: '/my/custom/node/path/.bin/stylelint'
|
40
|
+
files_to_lint: '\.(c|sc)ss$'
|
41
|
+
cli_options: '--config /custom/stylelintrc'
|
41
42
|
```
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pronto'
|
4
|
+
|
5
|
+
module Pronto
|
6
|
+
class Stylelint < Runner
|
7
|
+
class Config
|
8
|
+
EXECUTABLE_DEFAULT = 'stylelint'
|
9
|
+
FILES_TO_LINT_DEFAULT = /\.(c|sc|sa|le)ss$/.freeze
|
10
|
+
|
11
|
+
def stylelint_executable
|
12
|
+
stylelint_config['stylelint_executable'] || EXECUTABLE_DEFAULT
|
13
|
+
end
|
14
|
+
|
15
|
+
def cli_options
|
16
|
+
"#{stylelint_config['cli_options']} -f json".strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def files_to_lint
|
20
|
+
config_files_to_lint || FILES_TO_LINT_DEFAULT
|
21
|
+
end
|
22
|
+
|
23
|
+
def git_repo_path
|
24
|
+
@git_repo_path ||= Rugged::Repository.discover(File.expand_path(Dir.pwd)).workdir
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def config_files_to_lint
|
30
|
+
return unless stylelint_config['files_to_lint']
|
31
|
+
|
32
|
+
if stylelint_config['files_to_lint'].is_a?(Regexp)
|
33
|
+
stylelint_config['files_to_lint']
|
34
|
+
else
|
35
|
+
Regexp.new(stylelint_config['files_to_lint'])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def stylelint_config
|
40
|
+
@stylelint_config ||= Pronto::ConfigFile.new.to_h['stylelint'] || {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'pronto'
|
4
|
+
require 'shellwords'
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module Pronto
|
8
|
+
class Stylelint < Runner
|
9
|
+
class Linter
|
10
|
+
extend Forwardable
|
11
|
+
|
12
|
+
attr_reader :stylelint_config
|
13
|
+
|
14
|
+
def_delegators(
|
15
|
+
:stylelint_config,
|
16
|
+
:stylelint_executable,
|
17
|
+
:cli_options,
|
18
|
+
:git_repo_path
|
19
|
+
)
|
20
|
+
|
21
|
+
private :stylelint_executable, :cli_options, :git_repo_path
|
22
|
+
|
23
|
+
STYLELINT_FAILURE = 'Stylelint failed to run'
|
24
|
+
STATUS_CODES = {
|
25
|
+
0 => :success,
|
26
|
+
1 => :fatal_error,
|
27
|
+
2 => :lint_problem,
|
28
|
+
64 => :invalid_cli_usage,
|
29
|
+
78 => :invalid_configuration_file
|
30
|
+
}.freeze
|
31
|
+
|
32
|
+
def initialize(patch, stylelint_config)
|
33
|
+
@patch = patch
|
34
|
+
@stylelint_config = stylelint_config
|
35
|
+
@stylint_major_version = nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def run
|
39
|
+
Dir.chdir(git_repo_path) do
|
40
|
+
Open3.popen3(cli_command) do |_stdin, stdout, stderr, thread|
|
41
|
+
JSON.parse(
|
42
|
+
case thread_status(thread)
|
43
|
+
when :success, :lint_problem
|
44
|
+
out = stdout.read
|
45
|
+
out.empty? ? stderr.read : out
|
46
|
+
else
|
47
|
+
puts "#{STYLELINT_FAILURE} - #{thread_status(thread)}:\n#{stderr.read}"
|
48
|
+
'[]'
|
49
|
+
end
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def cli_command
|
58
|
+
"#{stylelint_executable} #{escaped_file_path} #{cli_options}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def escaped_file_path
|
62
|
+
Shellwords.escape(@patch.new_file_full_path.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Status codes:
|
66
|
+
# https://stylelint.io/user-guide/cli/#exit-codes
|
67
|
+
def thread_status(thread)
|
68
|
+
STATUS_CODES[thread.value.exitstatus] || :unknown
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/pronto/stylelint.rb
CHANGED
@@ -1,70 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pronto'
|
2
4
|
require 'shellwords'
|
5
|
+
require 'open3'
|
6
|
+
require 'pronto/stylelint/config'
|
7
|
+
require 'pronto/stylelint/linter'
|
3
8
|
|
4
9
|
module Pronto
|
5
10
|
class Stylelint < Runner
|
6
|
-
|
7
|
-
CONFIG_KEYS = %w(stylelint_executable files_to_lint cli_options).freeze
|
8
|
-
|
9
|
-
attr_writer :stylelint_executable, :cli_options
|
10
|
-
|
11
|
-
def initialize(patches, commit = nil)
|
12
|
-
super(patches, commit)
|
13
|
-
read_config
|
14
|
-
end
|
11
|
+
extend Forwardable
|
15
12
|
|
16
|
-
|
17
|
-
@stylelint_executable || 'stylelint'.freeze
|
18
|
-
end
|
13
|
+
attr_reader :stylelint_config
|
19
14
|
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def_delegators(
|
16
|
+
:stylelint_config,
|
17
|
+
:files_to_lint
|
18
|
+
)
|
19
|
+
private :files_to_lint
|
23
20
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def files_to_lint=(regexp)
|
29
|
-
@files_to_lint = regexp.is_a?(Regexp) ? regexp : Regexp.new(regexp)
|
30
|
-
end
|
31
|
-
|
32
|
-
def read_config
|
33
|
-
config_file = File.join(git_repo_path, CONFIG_FILE)
|
34
|
-
return unless File.exist?(config_file)
|
35
|
-
config = YAML.load_file(config_file)
|
21
|
+
def initialize(patches, commit = nil)
|
22
|
+
super
|
36
23
|
|
37
|
-
|
38
|
-
next unless config[config_key]
|
39
|
-
send("#{config_key}=", config[config_key])
|
40
|
-
end
|
24
|
+
@stylelint_config ||= Pronto::Stylelint::Config.new
|
41
25
|
end
|
42
26
|
|
43
27
|
def run
|
44
28
|
return [] if !@patches || @patches.count.zero?
|
45
29
|
|
46
30
|
@patches
|
47
|
-
.select { |patch| patch.additions
|
48
|
-
.
|
49
|
-
.
|
50
|
-
.flatten.compact
|
31
|
+
.select { |patch| patch.additions.positive? && style_file?(patch.new_file_full_path) }
|
32
|
+
.flat_map { |patch| inspect(patch) }
|
33
|
+
.compact
|
51
34
|
end
|
52
35
|
|
53
36
|
private
|
54
37
|
|
55
|
-
def git_repo_path
|
56
|
-
@git_repo_path ||= Rugged::Repository.discover(File.expand_path(Dir.pwd)).workdir
|
57
|
-
end
|
58
|
-
|
59
38
|
def inspect(patch)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
.map { |line| new_message(offence, line) }
|
67
|
-
end
|
39
|
+
clean_up_stylelint_output(Linter.new(patch, stylelint_config).run).flat_map do |offence|
|
40
|
+
patch
|
41
|
+
.added_lines
|
42
|
+
.select { |line| line.new_lineno == offence['line'] }
|
43
|
+
.map { |line| new_message(offence, line) }
|
44
|
+
end
|
68
45
|
end
|
69
46
|
|
70
47
|
def new_message(offence, line)
|
@@ -78,23 +55,14 @@ module Pronto
|
|
78
55
|
files_to_lint =~ path.to_s
|
79
56
|
end
|
80
57
|
|
81
|
-
def run_stylelint(patch)
|
82
|
-
Dir.chdir(git_repo_path) do
|
83
|
-
escaped_file_path = Shellwords.escape(patch.new_file_full_path.to_s)
|
84
|
-
JSON.parse(
|
85
|
-
`#{stylelint_executable} #{escaped_file_path} #{cli_options}`
|
86
|
-
)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
58
|
def clean_up_stylelint_output(output)
|
91
59
|
# 1. Filter out offences without a warning or error
|
92
60
|
# 2. Get the messages for that file
|
93
61
|
# 3. Ignore errors without a line number for now
|
94
62
|
output
|
95
|
-
.select { |offence| offence['warnings'].size
|
96
|
-
.
|
97
|
-
.
|
63
|
+
.select { |offence| offence['warnings'].size.positive? }
|
64
|
+
.flat_map { |offence| offence['warnings'] }
|
65
|
+
.select { |offence| offence['line'] }
|
98
66
|
end
|
99
67
|
end
|
100
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pronto-stylelint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Jalbert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pronto
|
@@ -50,34 +50,6 @@ dependencies:
|
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '2.0'
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rake
|
55
|
-
requirement: !ruby/object:Gem::Requirement
|
56
|
-
requirements:
|
57
|
-
- - "~>"
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version: '13.0'
|
60
|
-
type: :development
|
61
|
-
prerelease: false
|
62
|
-
version_requirements: !ruby/object:Gem::Requirement
|
63
|
-
requirements:
|
64
|
-
- - "~>"
|
65
|
-
- !ruby/object:Gem::Version
|
66
|
-
version: '13.0'
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: rspec
|
69
|
-
requirement: !ruby/object:Gem::Requirement
|
70
|
-
requirements:
|
71
|
-
- - "~>"
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
version: '3.4'
|
74
|
-
type: :development
|
75
|
-
prerelease: false
|
76
|
-
version_requirements: !ruby/object:Gem::Requirement
|
77
|
-
requirements:
|
78
|
-
- - "~>"
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: '3.4'
|
81
53
|
description:
|
82
54
|
email: kevin.j.jalbert@gmail.com
|
83
55
|
executables: []
|
@@ -89,6 +61,8 @@ files:
|
|
89
61
|
- LICENSE
|
90
62
|
- README.md
|
91
63
|
- lib/pronto/stylelint.rb
|
64
|
+
- lib/pronto/stylelint/config.rb
|
65
|
+
- lib/pronto/stylelint/linter.rb
|
92
66
|
- lib/pronto/stylelint/version.rb
|
93
67
|
homepage: https://github.com/kevinjalbert/pronto-stylelint
|
94
68
|
licenses:
|
@@ -110,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
84
|
version: '0'
|
111
85
|
requirements:
|
112
86
|
- stylelint (in PATH)
|
113
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.3.3
|
114
88
|
signing_key:
|
115
89
|
specification_version: 4
|
116
90
|
summary: Pronto runner for stylelint, the mighty, modern CSS linter.
|