immosquare-cleaner 0.1.70 → 0.1.72
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/lib/immosquare-cleaner/version.rb +1 -1
- data/linters/erb-lint-3.2.6.yml +14 -0
- data/linters/rubocop/cop/custom_cops/style/align_assignments.rb +171 -0
- data/linters/rubocop-3.4.1.yml +5 -0
- data/linters/rubocop.yml +4 -0
- data/package.json +4 -4
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83217701b85a19b792303464dac395f9762fbc05bf5a249a7be5de644b6a4f78
|
4
|
+
data.tar.gz: e828cb27a783a4fd8ead1a3aa538419802799ce3a841dcf84b708e3bfc215ff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71aa540fd2b292d764a6b66103f5990e527c8f2e96ed52c9adaf3e9df18d8ff4ac737e974582664a130b86c75e811d6a0dfb04e84c618fa6c45af8b1251c0e10
|
7
|
+
data.tar.gz: 3d2a6afa00b20a5295423969e9d1fc5dc7726e5624298c2e1b9d846c58e66d7ec97774c1f67cf5d875096cbb8af4b78f06db31f1d71844d9675b4f32ac1d3265
|
@@ -0,0 +1,14 @@
|
|
1
|
+
---
|
2
|
+
EnableDefaultLinters: true
|
3
|
+
linters:
|
4
|
+
NoJavascriptTagHelper:
|
5
|
+
enabled: false
|
6
|
+
SpaceInHtmlTag:
|
7
|
+
enabled: false
|
8
|
+
Rubocop:
|
9
|
+
enabled: true
|
10
|
+
rubocop_config:
|
11
|
+
inherit_from:
|
12
|
+
- linters/rubocop-3.2.6.yml
|
13
|
+
Layout/TrailingWhitespace:
|
14
|
+
Enabled: false
|
@@ -0,0 +1,171 @@
|
|
1
|
+
module RuboCop
|
2
|
+
module Cop
|
3
|
+
module CustomCops
|
4
|
+
module Style
|
5
|
+
##============================================================##
|
6
|
+
## This cop checks that consecutive assignments are aligned
|
7
|
+
##
|
8
|
+
## @example
|
9
|
+
## bad
|
10
|
+
## d2 = "xxx"
|
11
|
+
## variable = "yyy"
|
12
|
+
## very_long_variable = "zzz"
|
13
|
+
##
|
14
|
+
## good
|
15
|
+
## d2 = "xxx"
|
16
|
+
## variable = "yyy"
|
17
|
+
## very_long_variable = "zzz"
|
18
|
+
##============================================================##
|
19
|
+
class AlignAssignments < Base
|
20
|
+
|
21
|
+
extend AutoCorrector
|
22
|
+
|
23
|
+
MSG = "Align the assignment operators of consecutive assignments.".freeze
|
24
|
+
|
25
|
+
def on_new_investigation
|
26
|
+
@assignment_groups = []
|
27
|
+
@current_group = []
|
28
|
+
@last_assignment_line = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_lvasgn(node)
|
32
|
+
check_assignment(node)
|
33
|
+
end
|
34
|
+
|
35
|
+
def on_ivasgn(node)
|
36
|
+
check_assignment(node)
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_cvasgn(node)
|
40
|
+
check_assignment(node)
|
41
|
+
end
|
42
|
+
|
43
|
+
def on_gvasgn(node)
|
44
|
+
check_assignment(node)
|
45
|
+
end
|
46
|
+
|
47
|
+
def on_casgn(node)
|
48
|
+
check_assignment(node)
|
49
|
+
end
|
50
|
+
|
51
|
+
def on_masgn(node)
|
52
|
+
check_assignment(node)
|
53
|
+
end
|
54
|
+
|
55
|
+
##============================================================##
|
56
|
+
## Pour les assignments d'index (listing["key"] = ...)
|
57
|
+
##============================================================##
|
58
|
+
def on_send(node)
|
59
|
+
return unless node.method_name == :[]= && node.arguments.length == 2
|
60
|
+
|
61
|
+
check_assignment(node)
|
62
|
+
end
|
63
|
+
|
64
|
+
def on_investigation_end
|
65
|
+
finalize_current_group
|
66
|
+
process_groups
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
##============================================================##
|
72
|
+
## Vérifier que c'est bien un assignment simple (=) et pas (>=, <=, =>, etc.)
|
73
|
+
##============================================================##
|
74
|
+
def check_assignment(node)
|
75
|
+
return unless assignment_operator?(node)
|
76
|
+
|
77
|
+
add_to_group(node)
|
78
|
+
end
|
79
|
+
|
80
|
+
##============================================================##
|
81
|
+
## Vérifier si l'opérateur est un simple "=" (pas >=, <=, =>, etc.)
|
82
|
+
##============================================================##
|
83
|
+
def assignment_operator?(node)
|
84
|
+
##============================================================##
|
85
|
+
## Pour les send nodes (index assignment)
|
86
|
+
##============================================================##
|
87
|
+
return true if node.respond_to?(:method_name) && node.method_name == :[]=
|
88
|
+
|
89
|
+
##============================================================##
|
90
|
+
## Pour les assignments classiques
|
91
|
+
##============================================================##
|
92
|
+
source = node.source.strip
|
93
|
+
return false unless source.include?("=")
|
94
|
+
|
95
|
+
equals_pos = source.index("=")
|
96
|
+
return false if equals_pos > 0 && [">", "<"].include?(source[equals_pos - 1])
|
97
|
+
return false if equals_pos < source.length - 1 && source[equals_pos + 1] == ">"
|
98
|
+
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
##============================================================##
|
103
|
+
## Ajouter un assignment au groupe courant ou créer un nouveau groupe
|
104
|
+
##============================================================##
|
105
|
+
def add_to_group(node)
|
106
|
+
current_line = node.location.line
|
107
|
+
if @current_group.empty?
|
108
|
+
@current_group = [node]
|
109
|
+
elsif consecutive_lines?(@last_assignment_line, current_line)
|
110
|
+
@current_group << node
|
111
|
+
else
|
112
|
+
finalize_current_group
|
113
|
+
@current_group = [node]
|
114
|
+
end
|
115
|
+
@last_assignment_line = current_line
|
116
|
+
end
|
117
|
+
|
118
|
+
##============================================================##
|
119
|
+
## Retourne true si les deux lignes sont consécutives (pas de ligne vide entre elles)
|
120
|
+
##============================================================##
|
121
|
+
def consecutive_lines?(line1, line2)
|
122
|
+
gap = line2 - line1 - 1
|
123
|
+
gap == 0
|
124
|
+
end
|
125
|
+
|
126
|
+
##============================================================##
|
127
|
+
## Finaliser le groupe courant s'il contient plus d'un assignment
|
128
|
+
##============================================================##
|
129
|
+
def finalize_current_group
|
130
|
+
@assignment_groups << @current_group.dup if @current_group.length > 1
|
131
|
+
@current_group = []
|
132
|
+
@last_assignment_line = nil
|
133
|
+
end
|
134
|
+
|
135
|
+
##============================================================##
|
136
|
+
## Traiter tous les groupes d'assignments pour vérifier l'alignement
|
137
|
+
##============================================================##
|
138
|
+
def process_groups
|
139
|
+
@assignment_groups.each do |group|
|
140
|
+
check_and_correct_alignment(group)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
##============================================================##
|
145
|
+
## Vérifier l'alignement d'un groupe et corriger si nécessaire
|
146
|
+
##============================================================##
|
147
|
+
def check_and_correct_alignment(group)
|
148
|
+
lefts = group.map {|node| node.source.split("=")[0].to_s.strip.gsub(/\s+/, "").gsub(",", ", ") }
|
149
|
+
required_size = lefts.map(&:length).max + 1
|
150
|
+
|
151
|
+
group.each.with_index do |node, index|
|
152
|
+
current_source = node.source
|
153
|
+
new_left = lefts[index]
|
154
|
+
new_left += " " * (required_size - new_left.length)
|
155
|
+
split = current_source.split("=")
|
156
|
+
split[0] = new_left
|
157
|
+
expected_source = split.join("=")
|
158
|
+
|
159
|
+
if current_source != expected_source
|
160
|
+
add_offense(node, :message => MSG) do |corrector|
|
161
|
+
corrector.replace(node, expected_source)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
data/linters/rubocop-3.4.1.yml
CHANGED
@@ -3,6 +3,7 @@ require:
|
|
3
3
|
- rubocop/cop/style/method_call_with_args_parentheses_override
|
4
4
|
- rubocop/cop/custom_cops/style/comment_normalization
|
5
5
|
- rubocop/cop/custom_cops/style/font_awesome_normalization
|
6
|
+
- rubocop/cop/custom_cops/style/align_assignments
|
6
7
|
AllCops:
|
7
8
|
NewCops: enable
|
8
9
|
EnabledByDefault: false
|
@@ -97,5 +98,9 @@ CustomCops/Style/CommentNormalization:
|
|
97
98
|
Enabled: true
|
98
99
|
CustomCops/Style/FontAwesomeNormalization:
|
99
100
|
Enabled: true
|
101
|
+
CustomCops/Style/AlignAssignments:
|
102
|
+
Enabled: true
|
103
|
+
Layout/SpaceAroundOperators:
|
104
|
+
Enabled: false
|
100
105
|
Gemspec/RequireMFA:
|
101
106
|
Enabled: false
|
data/linters/rubocop.yml
CHANGED
@@ -2,6 +2,7 @@ require:
|
|
2
2
|
- rubocop/cop/style/method_call_with_args_parentheses_override
|
3
3
|
- rubocop/cop/custom_cops/style/comment_normalization
|
4
4
|
- rubocop/cop/custom_cops/style/font_awesome_normalization
|
5
|
+
- rubocop/cop/custom_cops/style/align_assignments
|
5
6
|
|
6
7
|
# Pour activer toutes les méthodes de Rubocop et activer le cache pour les gros fichiers
|
7
8
|
AllCops:
|
@@ -113,6 +114,9 @@ CustomCops/Style/CommentNormalization:
|
|
113
114
|
CustomCops/Style/FontAwesomeNormalization:
|
114
115
|
Enabled: true # On veut forcer l'utilisation du nom complet de la font awesome
|
115
116
|
|
117
|
+
CustomCops/Style/AlignAssignments:
|
118
|
+
Enabled: true # On veut forcer l'alignement des assignations consécutives
|
119
|
+
|
116
120
|
#################### GEM ###########################
|
117
121
|
Gemspec/RequireMFA:
|
118
122
|
Enabled: false # On ne veut pas obliger le MFA pour pusher un gem
|
data/package.json
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
"name": "immosquare-cleaner",
|
3
3
|
"private": true,
|
4
4
|
"dependencies": {
|
5
|
-
"@eslint/js": "^9.
|
6
|
-
"eslint": "^9.
|
5
|
+
"@eslint/js": "^9.29.0",
|
6
|
+
"eslint": "^9.29.0",
|
7
7
|
"eslint-plugin-align-assignments": "^1.1.2",
|
8
8
|
"eslint-plugin-align-import": "^1.0.0",
|
9
9
|
"eslint-plugin-erb": "^2.1.1",
|
10
10
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
11
|
-
"eslint-plugin-sonarjs": "^3.0.
|
12
|
-
"prettier": "^3.
|
11
|
+
"eslint-plugin-sonarjs": "^3.0.3",
|
12
|
+
"prettier": "^3.6.0"
|
13
13
|
},
|
14
14
|
"scripts": {"morning": "bundle update && bundle clean --force && bun update && bundle exec immosquare-cleaner 'package.json'"}
|
15
15
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: immosquare-cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.72
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- immosquare
|
@@ -146,12 +146,14 @@ files:
|
|
146
146
|
- lib/immosquare-cleaner/railtie.rb
|
147
147
|
- lib/immosquare-cleaner/version.rb
|
148
148
|
- lib/tasks/immosquare_cleaner.rake
|
149
|
+
- linters/erb-lint-3.2.6.yml
|
149
150
|
- linters/erb-lint-3.4.1.yml
|
150
151
|
- linters/erb-lint.yml
|
151
152
|
- linters/eslint.config.mjs
|
152
153
|
- linters/prettier.yml
|
153
154
|
- linters/rubocop-3.4.1.yml
|
154
155
|
- linters/rubocop.yml
|
156
|
+
- linters/rubocop/cop/custom_cops/style/align_assignments.rb
|
155
157
|
- linters/rubocop/cop/custom_cops/style/comment_normalization.rb
|
156
158
|
- linters/rubocop/cop/custom_cops/style/font_awesome_normalization.rb
|
157
159
|
- linters/rubocop/cop/style/method_call_with_args_parentheses_override.rb
|
@@ -175,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
- !ruby/object:Gem::Version
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.7.0
|
179
181
|
specification_version: 4
|
180
182
|
summary: A gem to lint and organize files in a Rails application.
|
181
183
|
test_files: []
|