rubocop-haml 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +70 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +12 -0
- data/config/default.yml +204 -0
- data/lib/rubocop/haml/config_loader.rb +50 -0
- data/lib/rubocop/haml/rubocop_extension.rb +10 -0
- data/lib/rubocop/haml/ruby_clip.rb +11 -0
- data/lib/rubocop/haml/ruby_clipper.rb +125 -0
- data/lib/rubocop/haml/ruby_extractor.rb +83 -0
- data/lib/rubocop/haml/version.rb +7 -0
- data/lib/rubocop/haml.rb +13 -0
- data/lib/rubocop-haml.rb +3 -0
- data/rubocop-haml.gemspec +33 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c475b080066b04c1f492d07ee74481b9b5ec3ebf2a1c43fec044a753c73f345c
|
4
|
+
data.tar.gz: bfed494b5893026c61d7e18227b611eedf882a1c9a4724d77f05c5628cfee3e4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6442a654ba39c5ac30185fa6002485c533f6f97bc217c1279d75edf037a3528cf1719aa7109f835952b4c0c1c7c4678c9c3b244406cc70ba458952020370864
|
7
|
+
data.tar.gz: 03bc8a2b3f5dfd23c1b047e639449dde0ed700e2536e6065cf9f00c29fb5b6dde40e5291669c55ff53e7b7f284f3701acf8f73bf0e9c9894e4a8ccd6066b3436
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-haml
|
3
|
+
- rubocop-rake
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
inherit_mode:
|
7
|
+
merge:
|
8
|
+
- Exclude
|
9
|
+
|
10
|
+
AllCops:
|
11
|
+
Exclude:
|
12
|
+
- spec/**/*.haml
|
13
|
+
NewCops: enable
|
14
|
+
TargetRubyVersion: 2.6
|
15
|
+
|
16
|
+
Gemspec/RequireMFA:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Naming/FileName:
|
23
|
+
Exclude:
|
24
|
+
- lib/rubocop-haml.rb
|
25
|
+
|
26
|
+
RSpec/ExampleLength:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
RSpec/MultipleExpectations:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
RSpec/NamedSubject:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/Documentation:
|
36
|
+
Enabled: false
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at r7kamura@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rubocop-haml (0.1.0)
|
5
|
+
hamli (~> 0.5)
|
6
|
+
rubocop (~> 1.45)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
ast (2.4.2)
|
12
|
+
diff-lcs (1.5.0)
|
13
|
+
hamli (0.5.1)
|
14
|
+
temple
|
15
|
+
json (2.6.3)
|
16
|
+
parallel (1.22.1)
|
17
|
+
parser (3.2.0.0)
|
18
|
+
ast (~> 2.4.1)
|
19
|
+
rainbow (3.1.1)
|
20
|
+
rake (13.0.6)
|
21
|
+
regexp_parser (2.7.0)
|
22
|
+
rexml (3.2.5)
|
23
|
+
rspec (3.12.0)
|
24
|
+
rspec-core (~> 3.12.0)
|
25
|
+
rspec-expectations (~> 3.12.0)
|
26
|
+
rspec-mocks (~> 3.12.0)
|
27
|
+
rspec-core (3.12.1)
|
28
|
+
rspec-support (~> 3.12.0)
|
29
|
+
rspec-expectations (3.12.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.12.0)
|
32
|
+
rspec-mocks (3.12.3)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.12.0)
|
35
|
+
rspec-support (3.12.0)
|
36
|
+
rubocop (1.45.1)
|
37
|
+
json (~> 2.3)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 3.2.0.0)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.8, < 3.0)
|
42
|
+
rexml (>= 3.2.5, < 4.0)
|
43
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
46
|
+
rubocop-ast (1.24.1)
|
47
|
+
parser (>= 3.1.1.0)
|
48
|
+
rubocop-capybara (2.17.0)
|
49
|
+
rubocop (~> 1.41)
|
50
|
+
rubocop-rake (0.6.0)
|
51
|
+
rubocop (~> 1.0)
|
52
|
+
rubocop-rspec (2.18.1)
|
53
|
+
rubocop (~> 1.33)
|
54
|
+
rubocop-capybara (~> 2.17)
|
55
|
+
ruby-progressbar (1.11.0)
|
56
|
+
temple (0.10.0)
|
57
|
+
unicode-display_width (2.4.2)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
x86_64-linux
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
rake
|
64
|
+
rspec
|
65
|
+
rubocop-haml!
|
66
|
+
rubocop-rake
|
67
|
+
rubocop-rspec
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
2.3.19
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Ryo Nakamura
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# rubocop-haml
|
2
|
+
|
3
|
+
[RuboCop](https://github.com/rubocop/rubocop) plugin for [Haml](https://github.com/haml/haml) template.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```
|
10
|
+
bundle add rubocop-haml
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```
|
16
|
+
gem install rubocop-haml
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Require `rubocop-haml` in your RuboCop config.
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
# .rubocop.yml
|
25
|
+
require:
|
26
|
+
- rubocop-haml
|
27
|
+
```
|
28
|
+
|
29
|
+
Now you can use RuboCop also for Haml templates.
|
30
|
+
|
31
|
+
```
|
32
|
+
$ bundle exec rubocop spec/fixtures/dummy.haml
|
33
|
+
Inspecting 1 file
|
34
|
+
C
|
35
|
+
|
36
|
+
Offenses:
|
37
|
+
|
38
|
+
spec/fixtures/dummy.haml:1:13: C: [Correctable] Style/CharacterLiteral: Do not use the character literal - use string literal instead.
|
39
|
+
%div(a="b #{?c}")
|
40
|
+
^^
|
41
|
+
spec/fixtures/dummy.haml:2:7: C: [Correctable] Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
|
42
|
+
%div{ :a => "b" }
|
43
|
+
^^^^^
|
44
|
+
spec/fixtures/dummy.haml:2:13: C: [Correctable] Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.
|
45
|
+
%div{ :a => "b" }
|
46
|
+
^^^
|
47
|
+
|
48
|
+
1 file inspected, 3 offenses detected, 3 offenses autocorrectable
|
49
|
+
```
|
data/Rakefile
ADDED
data/config/default.yml
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
inherit_mode:
|
2
|
+
merge:
|
3
|
+
- Exclude
|
4
|
+
- Include
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
Include:
|
8
|
+
- '**/*.haml'
|
9
|
+
|
10
|
+
Layout/ArgumentAlignment:
|
11
|
+
Exclude:
|
12
|
+
- '**/*.haml'
|
13
|
+
|
14
|
+
Layout/ArrayAlignment:
|
15
|
+
Exclude:
|
16
|
+
- '**/*.haml'
|
17
|
+
|
18
|
+
Layout/BlockAlignment:
|
19
|
+
Exclude:
|
20
|
+
- '**/*.haml'
|
21
|
+
|
22
|
+
Layout/ClosingParenthesisIndentation:
|
23
|
+
Exclude:
|
24
|
+
- '**/*.haml'
|
25
|
+
|
26
|
+
Layout/EmptyLineAfterGuardClause:
|
27
|
+
Exclude:
|
28
|
+
- '**/*.haml'
|
29
|
+
|
30
|
+
Layout/EndAlignment:
|
31
|
+
Exclude:
|
32
|
+
- '**/*.haml'
|
33
|
+
|
34
|
+
Layout/FirstArgumentIndentation:
|
35
|
+
Exclude:
|
36
|
+
- '**/*.haml'
|
37
|
+
|
38
|
+
Layout/FirstArrayElementIndentation:
|
39
|
+
Exclude:
|
40
|
+
- '**/*.haml'
|
41
|
+
|
42
|
+
Layout/FirstArrayElementLineBreak:
|
43
|
+
Exclude:
|
44
|
+
- '**/*.haml'
|
45
|
+
|
46
|
+
Layout/FirstHashElementIndentation:
|
47
|
+
Exclude:
|
48
|
+
- '**/*.haml'
|
49
|
+
|
50
|
+
Layout/FirstHashElementLineBreak:
|
51
|
+
Exclude:
|
52
|
+
- '**/*.haml'
|
53
|
+
|
54
|
+
Layout/FirstMethodArgumentLineBreak:
|
55
|
+
Exclude:
|
56
|
+
- '**/*.haml'
|
57
|
+
|
58
|
+
Layout/FirstParameterIndentation:
|
59
|
+
Exclude:
|
60
|
+
- '**/*.haml'
|
61
|
+
|
62
|
+
Layout/HashAlignment:
|
63
|
+
Exclude:
|
64
|
+
- '**/*.haml'
|
65
|
+
|
66
|
+
Layout/IndentationConsistency:
|
67
|
+
Exclude:
|
68
|
+
- '**/*.haml'
|
69
|
+
|
70
|
+
Layout/IndentationWidth:
|
71
|
+
Exclude:
|
72
|
+
- '**/*.haml'
|
73
|
+
|
74
|
+
Layout/LineEndStringConcatenationIndentation:
|
75
|
+
Exclude:
|
76
|
+
- '**/*.haml'
|
77
|
+
|
78
|
+
Layout/LineLength:
|
79
|
+
Exclude:
|
80
|
+
- '**/*.haml'
|
81
|
+
|
82
|
+
Layout/MultilineArrayBraceLayout:
|
83
|
+
Exclude:
|
84
|
+
- '**/*.haml'
|
85
|
+
|
86
|
+
Layout/MultilineAssignmentLayout:
|
87
|
+
Exclude:
|
88
|
+
- '**/*.haml'
|
89
|
+
|
90
|
+
Layout/MultilineHashBraceLayout:
|
91
|
+
Exclude:
|
92
|
+
- '**/*.haml'
|
93
|
+
|
94
|
+
Layout/MultilineMethodCallBraceLayout:
|
95
|
+
Exclude:
|
96
|
+
- '**/*.haml'
|
97
|
+
|
98
|
+
Layout/MultilineMethodCallIndentation:
|
99
|
+
Exclude:
|
100
|
+
- '**/*.haml'
|
101
|
+
|
102
|
+
Layout/MultilineMethodDefinitionBraceLayout:
|
103
|
+
Exclude:
|
104
|
+
- '**/*.haml'
|
105
|
+
|
106
|
+
Layout/MultilineOperationIndentation:
|
107
|
+
Exclude:
|
108
|
+
- '**/*.haml'
|
109
|
+
|
110
|
+
Layout/ParameterAlignment:
|
111
|
+
Exclude:
|
112
|
+
- '**/*.haml'
|
113
|
+
|
114
|
+
Layout/TrailingEmptyLines:
|
115
|
+
Exclude:
|
116
|
+
- '**/*.haml'
|
117
|
+
|
118
|
+
Layout/TrailingWhitespace:
|
119
|
+
Exclude:
|
120
|
+
- '**/*.haml'
|
121
|
+
|
122
|
+
Lint/EmptyFile:
|
123
|
+
Exclude:
|
124
|
+
- '**/*.haml'
|
125
|
+
|
126
|
+
Lint/SyntaxError:
|
127
|
+
Exclude:
|
128
|
+
- '**/*.haml'
|
129
|
+
|
130
|
+
Lint/UselessAssignment:
|
131
|
+
Exclude:
|
132
|
+
- '**/*.haml'
|
133
|
+
|
134
|
+
Lint/Void:
|
135
|
+
Exclude:
|
136
|
+
- '**/*.haml'
|
137
|
+
|
138
|
+
Metrics/BlockLength:
|
139
|
+
Exclude:
|
140
|
+
- '**/*.haml'
|
141
|
+
|
142
|
+
Metrics/BlockNesting:
|
143
|
+
Exclude:
|
144
|
+
- '**/*.haml'
|
145
|
+
|
146
|
+
Naming/FileName:
|
147
|
+
Exclude:
|
148
|
+
- '**/*.haml'
|
149
|
+
|
150
|
+
Style/FrozenStringLiteralComment:
|
151
|
+
Exclude:
|
152
|
+
- '**/*.haml'
|
153
|
+
|
154
|
+
Style/IdenticalConditionalBranches:
|
155
|
+
Exclude:
|
156
|
+
- '**/*.haml'
|
157
|
+
|
158
|
+
Style/IfUnlessModifier:
|
159
|
+
Exclude:
|
160
|
+
- '**/*.haml'
|
161
|
+
|
162
|
+
Style/MultilineTernaryOperator:
|
163
|
+
Exclude:
|
164
|
+
- '**/*.haml'
|
165
|
+
|
166
|
+
Style/NestedTernaryOperator:
|
167
|
+
Exclude:
|
168
|
+
- '**/*.haml'
|
169
|
+
|
170
|
+
Style/Next:
|
171
|
+
Exclude:
|
172
|
+
- '**/*.haml'
|
173
|
+
|
174
|
+
Style/ParallelAssignment:
|
175
|
+
Exclude:
|
176
|
+
- '**/*.haml'
|
177
|
+
|
178
|
+
Style/RescueModifier:
|
179
|
+
Exclude:
|
180
|
+
- '**/*.haml'
|
181
|
+
|
182
|
+
Style/Semicolon:
|
183
|
+
Exclude:
|
184
|
+
- '**/*.haml'
|
185
|
+
|
186
|
+
Style/TrailingCommaInArguments:
|
187
|
+
Exclude:
|
188
|
+
- '**/*.haml'
|
189
|
+
|
190
|
+
Style/TrailingCommaInArrayLiteral:
|
191
|
+
Exclude:
|
192
|
+
- '**/*.haml'
|
193
|
+
|
194
|
+
Style/TrailingCommaInHashLiteral:
|
195
|
+
Exclude:
|
196
|
+
- '**/*.haml'
|
197
|
+
|
198
|
+
Style/WhileUntilDo:
|
199
|
+
Exclude:
|
200
|
+
- '**/*.haml'
|
201
|
+
|
202
|
+
Style/WhileUntilModifier:
|
203
|
+
Exclude:
|
204
|
+
- '**/*.haml'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
|
5
|
+
module RuboCop
|
6
|
+
module Haml
|
7
|
+
# Merge default RuboCop config with plugin config.
|
8
|
+
class ConfigLoader
|
9
|
+
PLUGIN_CONFIG_PATH = ::File.expand_path(
|
10
|
+
'../../../config/default.yml',
|
11
|
+
__dir__
|
12
|
+
)
|
13
|
+
|
14
|
+
class << self
|
15
|
+
# @return [RuboCop::Config]
|
16
|
+
def call
|
17
|
+
new.call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @return [RuboCop::Config]
|
22
|
+
def call
|
23
|
+
RuboCop::ConfigLoader.merge_with_default(
|
24
|
+
plugin_config,
|
25
|
+
PLUGIN_CONFIG_PATH
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# @return [RuboCop::Config]
|
32
|
+
def plugin_config
|
33
|
+
config = ::RuboCop::Config.new(
|
34
|
+
plugin_config_hash,
|
35
|
+
PLUGIN_CONFIG_PATH
|
36
|
+
)
|
37
|
+
config.make_excludes_absolute
|
38
|
+
config
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Hash]
|
42
|
+
def plugin_config_hash
|
43
|
+
::RuboCop::ConfigLoader.send(
|
44
|
+
:load_yaml_configuration,
|
45
|
+
PLUGIN_CONFIG_PATH
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Haml
|
5
|
+
# Remove unnecessary part (e.g. `if`, `unless`, `do`, ...) from Ruby-ish code.
|
6
|
+
class RubyClipper
|
7
|
+
class << self
|
8
|
+
# @param [String] code
|
9
|
+
# @return [Hash]
|
10
|
+
def call(code)
|
11
|
+
new(code).call
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String] code
|
16
|
+
def initialize(code)
|
17
|
+
@code = code
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [RuboCop::Haml::RubyClip]
|
21
|
+
def call
|
22
|
+
[
|
23
|
+
PrecedingKeywordRemover,
|
24
|
+
TrailingDoRemover
|
25
|
+
].reduce(
|
26
|
+
RubyClip.new(
|
27
|
+
code: @code,
|
28
|
+
offset: 0
|
29
|
+
)
|
30
|
+
) do |previous, callable|
|
31
|
+
result = callable.call(previous.code)
|
32
|
+
RubyClip.new(
|
33
|
+
code: result.code,
|
34
|
+
offset: previous.offset + result.offset
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Remove preceding keyword.
|
40
|
+
class PrecedingKeywordRemover
|
41
|
+
REGEXP = /
|
42
|
+
\A
|
43
|
+
(?:
|
44
|
+
begin
|
45
|
+
| case
|
46
|
+
| else
|
47
|
+
| elsif
|
48
|
+
| ensure
|
49
|
+
| if
|
50
|
+
| rescue
|
51
|
+
| unless
|
52
|
+
| until
|
53
|
+
| when
|
54
|
+
| while
|
55
|
+
| for[ \t]+\w+[ \t]+in
|
56
|
+
)
|
57
|
+
[ \t]
|
58
|
+
/x.freeze
|
59
|
+
|
60
|
+
class << self
|
61
|
+
# @param [String] code
|
62
|
+
# @return [RubyClip]
|
63
|
+
def call(code)
|
64
|
+
new(code).call
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [String] code
|
69
|
+
def initialize(code)
|
70
|
+
@code = code
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [Hash]
|
74
|
+
def call
|
75
|
+
data = @code.match(REGEXP)
|
76
|
+
if data
|
77
|
+
offset = data[0].length
|
78
|
+
RubyClip.new(
|
79
|
+
code: @code[offset..],
|
80
|
+
offset: offset
|
81
|
+
)
|
82
|
+
else
|
83
|
+
RubyClip.new(
|
84
|
+
code: @code,
|
85
|
+
offset: 0
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Remove trailing `do`.
|
92
|
+
class TrailingDoRemover
|
93
|
+
REGEXP = /
|
94
|
+
[ \t]
|
95
|
+
do
|
96
|
+
[ \t]*
|
97
|
+
(\|[^|]*\|)?
|
98
|
+
[ \t]*
|
99
|
+
\Z
|
100
|
+
/x.freeze
|
101
|
+
|
102
|
+
class << self
|
103
|
+
# @param [String] code
|
104
|
+
# @return [RubyClip]
|
105
|
+
def call(code)
|
106
|
+
new(code).call
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# @param [String] code
|
111
|
+
def initialize(code)
|
112
|
+
@code = code
|
113
|
+
end
|
114
|
+
|
115
|
+
# @return [Hash]
|
116
|
+
def call
|
117
|
+
RubyClip.new(
|
118
|
+
code: @code.sub(REGEXP, ''),
|
119
|
+
offset: 0
|
120
|
+
)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rubocop'
|
4
|
+
require 'hamli'
|
5
|
+
|
6
|
+
module RuboCop
|
7
|
+
module Haml
|
8
|
+
# Extract Ruby codes from Haml template.
|
9
|
+
class RubyExtractor
|
10
|
+
class << self
|
11
|
+
# @param [RuboCop::ProcessedSource] processed_source
|
12
|
+
# @return [Array<RuboCop::ProcessedSource>, nil]
|
13
|
+
def call(processed_source)
|
14
|
+
new(processed_source).call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [RuboCop::ProcessedSource] processed_source
|
19
|
+
def initialize(processed_source)
|
20
|
+
@processed_source = processed_source
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Array<RuboCop::ProcessedSource>, nil]
|
24
|
+
def call
|
25
|
+
return unless supported_file_path_pattern?
|
26
|
+
|
27
|
+
ruby_ranges.map do |(begin_, end_)|
|
28
|
+
clip = RubyClipper.new(template_source[begin_...end_]).call
|
29
|
+
{
|
30
|
+
offset: begin_ + clip[:offset],
|
31
|
+
processed_source: ::RuboCop::ProcessedSource.new(
|
32
|
+
clip[:code],
|
33
|
+
@processed_source.ruby_version,
|
34
|
+
file_path
|
35
|
+
)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
# @return [Array] Haml AST, represented in S-expression.
|
43
|
+
def ast
|
44
|
+
::Hamli::Filters::Interpolation.new.call(
|
45
|
+
::Hamli::Parser.new(file: file_path).call(template_source)
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @return [String, nil]
|
50
|
+
def file_path
|
51
|
+
@processed_source.path
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Array<Array<Integer>>]
|
55
|
+
def ruby_ranges
|
56
|
+
result = []
|
57
|
+
traverse(ast) do |begin_, end_|
|
58
|
+
result << [begin_, end_]
|
59
|
+
end
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Boolean]
|
64
|
+
def supported_file_path_pattern?
|
65
|
+
file_path&.end_with?('.haml')
|
66
|
+
end
|
67
|
+
|
68
|
+
def traverse(node, &block)
|
69
|
+
return unless node.instance_of?(::Array)
|
70
|
+
|
71
|
+
block.call(node[2], node[3]) if node[0] == :hamli && node[1] == :position
|
72
|
+
node.each do |element|
|
73
|
+
traverse(element, &block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# @return [String]
|
78
|
+
def template_source
|
79
|
+
@processed_source.raw_source
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/rubocop/haml.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Haml
|
5
|
+
autoload :ConfigLoader, 'rubocop/haml/config_loader'
|
6
|
+
autoload :RubyClip, 'rubocop/haml/ruby_clip'
|
7
|
+
autoload :RubyClipper, 'rubocop/haml/ruby_clipper'
|
8
|
+
autoload :RubyExtractor, 'rubocop/haml/ruby_extractor'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
require_relative 'haml/rubocop_extension'
|
13
|
+
require_relative 'haml/version'
|
data/lib/rubocop-haml.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/rubocop/haml/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'rubocop-haml'
|
7
|
+
spec.version = Rubocop::Haml::VERSION
|
8
|
+
spec.authors = ['Ryo Nakamura']
|
9
|
+
spec.email = ['r7kamura@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'RuboCop plugin for Haml template.'
|
12
|
+
spec.homepage = 'https://github.com/r7kamura/rubocop-haml'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = spec.homepage
|
18
|
+
spec.metadata['changelog_uri'] = "#{spec.homepage}/releases"
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(__dir__) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_dependency 'hamli', '~> 0.5'
|
32
|
+
spec.add_dependency 'rubocop', '~> 1.45'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubocop-haml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hamli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.45'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.45'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- r7kamura@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- config/default.yml
|
57
|
+
- lib/rubocop-haml.rb
|
58
|
+
- lib/rubocop/haml.rb
|
59
|
+
- lib/rubocop/haml/config_loader.rb
|
60
|
+
- lib/rubocop/haml/rubocop_extension.rb
|
61
|
+
- lib/rubocop/haml/ruby_clip.rb
|
62
|
+
- lib/rubocop/haml/ruby_clipper.rb
|
63
|
+
- lib/rubocop/haml/ruby_extractor.rb
|
64
|
+
- lib/rubocop/haml/version.rb
|
65
|
+
- rubocop-haml.gemspec
|
66
|
+
homepage: https://github.com/r7kamura/rubocop-haml
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata:
|
70
|
+
homepage_uri: https://github.com/r7kamura/rubocop-haml
|
71
|
+
source_code_uri: https://github.com/r7kamura/rubocop-haml
|
72
|
+
changelog_uri: https://github.com/r7kamura/rubocop-haml/releases
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 2.6.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.3.7
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: RuboCop plugin for Haml template.
|
92
|
+
test_files: []
|