immosquare-cleaner 0.1.57 → 0.1.58

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f1cc74ae056259578131aca9c6898a8ba92d8ca64d0f187aed286ad106e4ef62
4
- data.tar.gz: f77ff918048caf7e21ad6c3a671efc18ee4dd316a42f066c109f37d247fd2047
3
+ metadata.gz: '0991478e3031627640bda4872fdb498d81ce11e81a345ddcfd73ace50d8cbd27'
4
+ data.tar.gz: 1754443c996d12a2dac69dabee15abef287f5035cdcdf593b195202a576e52a3
5
5
  SHA512:
6
- metadata.gz: 8e6d0bf312d5dc56877dcea0f7b0c0d6b5076ca7bb0feb77242935707048ddfb389fba51d79d6fa2ff7547d71f75306baff6e82a0d1459e77493d044b4635b8b
7
- data.tar.gz: cc91ba381c31bfd30ffcb7ccc185563216bd3fad9423f96cbfdeeab97bdd680e514935326dba3e01d0d82f80bcfc520962143762496bcc230aeca44cfa4bb286
6
+ metadata.gz: 15390799d3d8adbf845bcb48a0c78fbd1f27a96b1d5064646d1ecceb2bb23f74c44fe73c68df1c11971a7d836f40a3b389fe8c0f0872098ad9fdf2b83a414189
7
+ data.tar.gz: 983088c24e6d8b322eb05f0f0bac88a87a16e23751fde92466df173e10aa901f2661f8b5416b93373a23f74ff8e6314849e7caf832d861c1d022731c22f000cd
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.57".freeze
2
+ VERSION = "0.1.58".freeze
3
3
  end
@@ -6,13 +6,15 @@ module RuboCop
6
6
 
7
7
  extend AutoCorrector
8
8
 
9
- MSG = "Comments should be normalized with the standard format if start with ##".freeze
10
- BORDER_LINE = "###{"=" * 60}##".freeze
11
- SPACE = " ".freeze
9
+ MSG = "Comments should be normalized with the standard format if start with ##".freeze
10
+ BORDER_LINE = "###{"=" * 60}##".freeze
11
+ SPACE = " ".freeze
12
+ INSIDE_SEPARATOR = "###{SPACE}---------".freeze
12
13
 
13
14
  def on_new_investigation
14
15
  comment_blocks = find_comment_blocks(processed_source.comments)
15
16
 
17
+
16
18
  comment_blocks.each do |block|
17
19
  if needs_correction?(block)
18
20
  ##============================================================##
@@ -45,7 +47,7 @@ module RuboCop
45
47
  def find_comment_blocks(comments)
46
48
  blocks = []
47
49
  current_block = []
48
- filtered_comments = comments.select {|comment| line_content(comment).strip.start_with?("##") }
50
+ filtered_comments = comments.select {|comment| line_content(comment).strip.start_with?("##") || comment.text.start_with?("#=") }
49
51
 
50
52
  filtered_comments.each do |comment|
51
53
  if current_block.empty? || comment.location.line == current_block.last.location.line + 1
@@ -69,6 +71,15 @@ module RuboCop
69
71
  def needs_correction?(block)
70
72
  return false if block.compact.empty?
71
73
 
74
+ ##============================================================##
75
+ ## un block de commentaires ne peut pas être composé de moins de 3 lignes (border, body, border)
76
+ ##============================================================##
77
+ return true if block.size < 3
78
+
79
+ ##============================================================##
80
+ ## On retourne true si une ligne du block contient que les caractères de bordure sans que cela soit une ligne de bordure
81
+ ##============================================================##
82
+ return true if block[1..-2].any? {|comment| comment.text.chars.uniq.compact.sort == [" ", "#", "="] }
72
83
 
73
84
  return false if block.first.text == BORDER_LINE &&
74
85
  block.last.text == BORDER_LINE &&
@@ -79,6 +90,7 @@ module RuboCop
79
90
  comment.text.start_with?("##=")
80
91
  end
81
92
 
93
+
82
94
  true
83
95
  end
84
96
 
@@ -93,8 +105,8 @@ module RuboCop
93
105
  ##============================================================##
94
106
  text = comment.text.to_s.strip
95
107
  text = text.gsub(/^##(?![=\s])/, "###{SPACE}")
96
- if text.start_with?("##=")
97
- index == 0 || index == block.size - 1 ? nil : "###{SPACE}---------"
108
+ if text.start_with?("##=") || text.start_with?("#=")
109
+ index == 0 || index == block.size - 1 ? nil : INSIDE_SEPARATOR
98
110
  else
99
111
  text = "###{SPACE}#{text}" if !text.start_with?("###{SPACE}")
100
112
  text = text.chomp("##").strip
@@ -102,6 +114,14 @@ module RuboCop
102
114
  end
103
115
  end.compact
104
116
 
117
+ ##============================================================##
118
+ ## On efface les lignes du body qui serait des lignes de bordure (bien formatée ou non)
119
+ ##============================================================##
120
+ body = body.map do |line|
121
+ chars = line.chars.uniq.compact.sort
122
+ [[" ", "#", "="], ["#", "="]].include?(chars) ? nil : line
123
+ end.compact
124
+
105
125
 
106
126
  ##============================================================##
107
127
  ## Le block va être remis à la place du block original sur
@@ -124,7 +144,6 @@ module RuboCop
124
144
  end
125
145
 
126
146
 
127
-
128
147
  end
129
148
  end
130
149
  end
@@ -0,0 +1,97 @@
1
+ ---
2
+ require:
3
+ - rubocop/cop/style/method_call_with_args_parentheses_override
4
+ - rubocop/cop/custom_cops/style/comment_normalization
5
+ AllCops:
6
+ NewCops: enable
7
+ EnabledByDefault: false
8
+ UseCache: true
9
+ SuggestExtensions: false
10
+ ActiveSupportExtensionsEnabled: true
11
+ TargetRubyVersion: 3.4.1
12
+ Metrics:
13
+ Enabled: false
14
+ Lint/UselessAssignment:
15
+ Enabled: false
16
+ Lint/RescueException:
17
+ Enabled: false
18
+ Lint/UnusedMethodArgument:
19
+ Enabled: false
20
+ Naming/VariableNumber:
21
+ Enabled: false
22
+ Naming/FileName:
23
+ Enabled: false
24
+ Naming/MethodParameterName:
25
+ MinNameLength: 1
26
+ Layout/LeadingEmptyLines:
27
+ Enabled: false
28
+ Layout/InitialIndentation:
29
+ Enabled: false
30
+ Layout/TrailingEmptyLines:
31
+ Enabled: false
32
+ Layout/ExtraSpacing:
33
+ Enabled: false
34
+ Layout/LineLength:
35
+ Enabled: false
36
+ Layout/TrailingWhitespace:
37
+ Enabled: true
38
+ Layout/EmptyLines:
39
+ Enabled: false
40
+ Layout/SpaceInsideBlockBraces:
41
+ SpaceBeforeBlockParameters: false
42
+ Layout/EmptyLinesAroundClassBody:
43
+ EnforcedStyle: empty_lines
44
+ Layout/FirstHashElementIndentation:
45
+ EnforcedStyle: consistent
46
+ Layout/ArgumentAlignment:
47
+ EnforcedStyle: with_fixed_indentation
48
+ Layout/HashAlignment:
49
+ EnforcedHashRocketStyle: table
50
+ Layout/MultilineAssignmentLayout:
51
+ EnforcedStyle: same_line
52
+ Layout/SpaceInsideHashLiteralBraces:
53
+ EnforcedStyle: no_space
54
+ Layout/MultilineMethodCallIndentation:
55
+ EnforcedStyle: indented
56
+ Style/CombinableLoops:
57
+ Enabled: false
58
+ Style/SingleArgumentDig:
59
+ Enabled: false
60
+ Style/RedundantBegin:
61
+ Enabled: false
62
+ Style/MultilineTernaryOperator:
63
+ Enabled: false
64
+ Style/NestedTernaryOperator:
65
+ Enabled: false
66
+ Style/MultilineIfModifier:
67
+ Enabled: false
68
+ Style/FrozenStringLiteralComment:
69
+ Enabled: false
70
+ Style/Next:
71
+ Enabled: false
72
+ Style/Documentation:
73
+ Enabled: false
74
+ Style/IfUnlessModifierOfIfUnless:
75
+ Enabled: false
76
+ Style/NegatedIf:
77
+ Enabled: false
78
+ Style/FormatStringToken:
79
+ EnforcedStyle: template
80
+ Style/NumericPredicate:
81
+ EnforcedStyle: comparison
82
+ Style/StringLiterals:
83
+ EnforcedStyle: double_quotes
84
+ Style/StringLiteralsInInterpolation:
85
+ EnforcedStyle: double_quotes
86
+ Style/HashSyntax:
87
+ EnforcedStyle: hash_rockets
88
+ Style/WordArray:
89
+ EnforcedStyle: brackets
90
+ Style/SymbolArray:
91
+ EnforcedStyle: brackets
92
+ Style/MethodCallWithArgsParentheses:
93
+ Enabled: true
94
+ CustomCops/Style/CommentNormalization:
95
+ Enabled: true
96
+ Gemspec/RequireMFA:
97
+ Enabled: false
data/linters/rubocop.yml CHANGED
@@ -1,6 +1,5 @@
1
1
  require:
2
2
  - rubocop/cop/style/method_call_with_args_parentheses_override
3
- - rubocop/cop/custom_cops/style/use_credentials_instead_of_env
4
3
  - rubocop/cop/custom_cops/style/comment_normalization
5
4
 
6
5
  # Pour activer toutes les méthodes de Rubocop et activer le cache pour les gros fichiers
@@ -107,8 +106,6 @@ Style/MethodCallWithArgsParentheses:
107
106
  Enabled: true # On veut forcer les parenthèses où elles sont utilises pour rendre le code plus propre
108
107
 
109
108
  #################### CUSTOMS ###########################
110
- CustomCops/Style/UseCredentialsInsteadOfEnv:
111
- Enabled: true # On veut forcer l'utilisation de credentials au lieu de ENV pour les secrets
112
109
  CustomCops/Style/CommentNormalization:
113
110
  Enabled: true # On veut forcer la normalisation des commentaires
114
111
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.57
4
+ version: 0.1.58
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-12-24 00:00:00.000000000 Z
10
+ date: 2025-01-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: erb_lint
@@ -131,9 +131,9 @@ files:
131
131
  - linters/jscodeshift/arrow-function-transform.js
132
132
  - linters/prettier.yml
133
133
  - linters/rubocop-3.3.6.yml
134
+ - linters/rubocop-3.4.1.yml
134
135
  - linters/rubocop.yml
135
136
  - linters/rubocop/cop/custom_cops/style/comment_normalization.rb
136
- - linters/rubocop/cop/custom_cops/style/use_credentials_instead_of_env.rb
137
137
  - linters/rubocop/cop/style/method_call_with_args_parentheses_override.rb
138
138
  - node_modules/.bin/acorn
139
139
  - node_modules/.bin/babylon
@@ -1,49 +0,0 @@
1
- module RuboCop
2
- module Cop
3
- module CustomCops
4
- module Style
5
- ##============================================================##
6
- ## Custom Cop: UseCredentialsInsteadOfEnv
7
- ## To replace ENV.fetch with Rails.application.credentials
8
- ##============================================================##
9
- class UseCredentialsInsteadOfEnv < Base
10
-
11
- extend AutoCorrector
12
-
13
- MSG = "Use Rails.application.credentials instead of ENV.fetch".freeze
14
-
15
- ##============================================================##
16
- ## Node Matcher
17
- ##============================================================##
18
- def_node_matcher :env_fetch?, <<~PATTERN
19
- (send (const nil? :ENV) :fetch ...)
20
- PATTERN
21
-
22
- def on_send(node)
23
- return if !env_fetch?(node)
24
-
25
- ##============================================================##
26
- ## ENV.fetch("hello_world", nil) => Rails.application.credentials.hello_world
27
- ## ENV.fetch("hello_world_#{user_id}", nil) => Rails.application.credentials["hello_world_#{user_id}"]
28
- ##============================================================##
29
- key = node.arguments.first
30
- value = key.type == :dstr ? "[#{key.source}]" : ".#{key.source.delete('"')}"
31
-
32
- ##============================================================##
33
- ## Skip if key starts with BUNDLER_ or RAILS_ or BUNDLE_
34
- ##============================================================##
35
- return if key.source.delete('"').start_with?("BUNDLER_", "BUNDLE_", "RAILS_")
36
-
37
- ##============================================================##
38
- ## Add offense
39
- ##============================================================##
40
- add_offense(node) do |corrector|
41
- corrector.replace(node, "Rails.application.credentials#{value}")
42
- end
43
- end
44
-
45
- end
46
- end
47
- end
48
- end
49
- end