immosquare-cleaner 0.1.53 → 0.1.54

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: 9196f9f8512b09892046a08e62a7d88651c64a303de24c06939f879892e52cf7
4
- data.tar.gz: ebb02f2943eec1220d90bd122fb8eb74e93924e08e140d03d869dc9a046f2f35
3
+ metadata.gz: af665f762e14a1bdcd0e70e34ce6d520db0acf3c4adffc8a418877fcffede1c4
4
+ data.tar.gz: 7e8b7dfff3619c6a314b22f0a09959acec888e63d049a6c9dff311f495c2117a
5
5
  SHA512:
6
- metadata.gz: fad7b547a77506b0c92bc672a395e0ccee00ca2f7092fb838d9b621138e059bd57bc74e5317d0fbb4228a65899d1c591704e2f30fa8e0118afa0ce65c133da3a
7
- data.tar.gz: ea5754c29eaf9d6bcd7f2e7b1531808d8a540a021f28f446d36cbd159ccd400c33cf2a1ed691da9b43ce096bf86408f5b4f625f3ed897d417029daa336b6e1da
6
+ metadata.gz: 2fc51d6c15c4451af904583f070738e09e81e56c0e5c168a6d28cd7af0a936dfa4f223752b689a9884524762b785f14ce2757fd2f12956c1b4ef8236736e2393
7
+ data.tar.gz: 63225554da9fbc25c57480eee2f393eb784b1da35e8eaeb3c7eb2f7d898c2c607d5cad1b4ed204ff3683f921df9e17d22b2decb8f7b87406c5a98d3739efa351
@@ -4,9 +4,9 @@ require "immosquare-cleaner"
4
4
  require "optparse"
5
5
 
6
6
 
7
- ##===========================================================================##
7
+ ##============================================================##
8
8
  ## We check if bun.sh is installed
9
- ##===========================================================================##
9
+ ##============================================================##
10
10
  def bun_installed?
11
11
  system("which bun > /dev/null 2>&1")
12
12
  end
@@ -18,49 +18,49 @@ end
18
18
 
19
19
 
20
20
  options = {}
21
- ##===========================================================================##
22
- ## optparse is a standard library of ruby, it's used to parse command line ##
23
- ##===========================================================================##
21
+ ##============================================================##
22
+ ## optparse is a standard library of ruby, it's used to parse command line
23
+ ##============================================================##
24
24
  OptionParser.new do |opts|
25
25
  opts.banner = "Usage: immosquare-cleaner [options] file"
26
26
 
27
- ##===========================================================================##
28
- ## Capture all single-letter options (like '-t', '-a', etc.) ##
29
- ##===========================================================================##
27
+ ##============================================================##
28
+ ## Capture all single-letter options (like '-t', '-a', etc.)
29
+ ##============================================================##
30
30
  ("a".."z").each do |letter|
31
31
  opts.on("-#{letter} [OPTION]", "Option -#{letter}") do |value|
32
32
  options[letter.to_sym] = value
33
33
  end
34
34
  end
35
35
 
36
- ##===========================================================================##
37
- ## If you also want to capture longer options, add them here ##
38
- ## Example: ##
39
- ## opts.on("--tag TAG", "Tag option") do |t| ##
40
- ## options[:tag] = t ##
41
- ## end ##
42
- ##===========================================================================##
36
+ ##============================================================##
37
+ ## If you also want to capture longer options, add them here
38
+ ## Example:
39
+ ## opts.on("--tag TAG", "Tag option") do |t|
40
+ ## options[:tag] = t
41
+ ## end
42
+ ##============================================================##
43
43
  end.parse!
44
44
 
45
- ##===========================================================================##
46
- ## Check if the file path is provided ##
47
- ##===========================================================================##
45
+ ##============================================================##
46
+ ## Check if the file path is provided
47
+ ##============================================================##
48
48
  file_path = ARGV[0]
49
49
  if !file_path
50
50
  puts("Error: Please provide a file path.")
51
51
  exit 1
52
52
  end
53
53
 
54
- ##===========================================================================##
55
- ## Check if the file exists ##
56
- ##===========================================================================##
54
+ ##============================================================##
55
+ ## Check if the file exists
56
+ ##============================================================##
57
57
  if !File.exist?(file_path)
58
58
  puts("Error: The file '#{file_path}' does not exist.")
59
59
  exit 1
60
60
  end
61
61
 
62
62
 
63
- ##===========================================================================##
64
- ## We can now call the clean method, passing the file path and options ##
65
- ##===========================================================================##
63
+ ##============================================================##
64
+ ## We can now call the clean method, passing the file path and options
65
+ ##============================================================##
66
66
  ImmosquareCleaner.clean(file_path, **options)
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.53".freeze
2
+ VERSION = "0.1.54".freeze
3
3
  end
@@ -7,24 +7,24 @@ require_relative "immosquare-cleaner/configuration"
7
7
  require_relative "immosquare-cleaner/markdown"
8
8
  require_relative "immosquare-cleaner/railtie" if defined?(Rails)
9
9
 
10
- ##===========================================================================##
10
+ ##============================================================##
11
11
  ## Importing the 'English' library allows us to use more human-readable
12
12
  ## global variables, such as $INPUT_RECORD_SEPARATOR instead of $/,
13
13
  ## which enhances code clarity and makes it easier to understand
14
14
  ## the purpose of these variables in our code.
15
- ##===========================================================================##
15
+ ##============================================================##
16
16
  module ImmosquareCleaner
17
17
  class << self
18
18
 
19
- ##===========================================================================##
19
+ ##============================================================##
20
20
  ## Constants
21
- ##===========================================================================##
21
+ ##============================================================##
22
22
  SHEBANG = "#!/usr/bin/env ruby".freeze
23
23
  RUBY_FILES = [".rb", ".rake", "Gemfile", "Rakefile", ".axlsx", ".gemspec", ".ru", ".podspec", ".jbuilder", ".rabl", ".thor", "config.ru", "Berksfile", "Capfile", "Guardfile", "Podfile", "Thorfile", "Vagrantfile"].freeze
24
24
 
25
- ##===========================================================================##
25
+ ##============================================================##
26
26
  ## Gem configuration
27
- ##===========================================================================##
27
+ ##============================================================##
28
28
  attr_writer :configuration
29
29
 
30
30
  def configuration
@@ -157,10 +157,10 @@ module ImmosquareCleaner
157
157
  File.expand_path("..", __dir__)
158
158
  end
159
159
 
160
- ##===========================================================================##
160
+ ##============================================================##
161
161
  ## We change the current directory to the gem root to ensure the gem's paths
162
162
  ## are used when executing the commands
163
- ##===========================================================================##
163
+ ##============================================================##
164
164
  def launch_cmds(cmds)
165
165
  Dir.chdir(gem_root) do
166
166
  cmds.each {|cmd| system(cmd) }
@@ -0,0 +1,122 @@
1
+ module RuboCop
2
+ module Cop
3
+ module CustomCops
4
+ ##============================================================##
5
+ ## Ce cop dépend du module PRE pour être lancer top dans le
6
+ ## processus de vérification pour que ensuite Layout/CommentIndentation
7
+ ## intende correctement les commentaires modifiés.
8
+ ## Department Layout (y compris Layout/CommentIndentation)
9
+ ## Department Lint
10
+ ## Department Style
11
+ ## Department Metricstoto
12
+ ##============================================================##
13
+ module Pre
14
+ class CommentNormalization < Base
15
+
16
+ extend AutoCorrector
17
+
18
+ MSG = "Comments should be normalized with the standard format if start with ##".freeze
19
+ BORDER_LINE = "###{"=" * 60}##".freeze
20
+
21
+ ##============================================================##
22
+ ## 1 - var js, fjs = d.getElementsByTagName(s)[0];
23
+ ## équivaut à var js = null et var fjs(first JS) d.getElementsByTagName(s)[0]
24
+ ## On compile le fichier avec Terser pour qu'il soit minifié
25
+ ##============================================================##
26
+ def on_new_investigation
27
+ comment_blocks = find_comment_blocks(processed_source.comments)
28
+
29
+ comment_blocks.each do |block|
30
+ add_offense(block.first) do |corrector|
31
+ corrector.replace(range_for_block(block), normalize_comment_block(block))
32
+ end if needs_correction?(block)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+
39
+ ##============================================================##
40
+ ## On ne veut traiter que les commentaires qui :
41
+ ## - commencent par ## (et non #)
42
+ ## - ne sont pas des commentaires de fin de ligne ruby
43
+ ##============================================================##
44
+ def find_comment_blocks(comments)
45
+ blocks = []
46
+ current_block = []
47
+ filtered_comments = comments.select {|comment| current_line(comment).strip.start_with?("##") }
48
+
49
+ filtered_comments.each do |comment|
50
+ if current_block.empty? || consecutive_comments?(current_block.last, comment)
51
+ current_block << comment
52
+ else
53
+ blocks << current_block unless current_block.empty?
54
+ current_block = [comment]
55
+ end
56
+ end
57
+
58
+ blocks << current_block unless current_block.empty?
59
+ blocks
60
+ end
61
+
62
+ ##============================================================##
63
+ ## Pour récupérer le contenu de la ligne courante
64
+ ##============================================================##
65
+ def current_line(comment)
66
+ processed_source.lines[comment.location.line - 1]
67
+ end
68
+
69
+ def consecutive_comments?(previous_comment, current_comment)
70
+ return false unless previous_comment && current_comment
71
+
72
+ previous_line = previous_comment.location.line
73
+ current_line = current_comment.location.line
74
+ current_line == previous_line + 1
75
+ end
76
+
77
+ def needs_correction?(block)
78
+ indent = indentation(block.first)
79
+ expected_border = "#{indent}#{BORDER_LINE}"
80
+
81
+ return false if block.first.text == expected_border &&
82
+ block.last.text == expected_border &&
83
+ block.all? {|comment| comment.text.start_with?("#{indent}## ") || comment.text == expected_border }
84
+
85
+ true
86
+ end
87
+
88
+ def normalize_comment_block(block)
89
+ indent = indentation(block.first)
90
+ normalized_lines = []
91
+
92
+ normalized_lines << "#{indent}#{BORDER_LINE}"
93
+
94
+ block.each do |comment|
95
+ text = comment.text.to_s.strip
96
+ next if text.start_with?("##=")
97
+
98
+ text = "## #{text}" if !text.start_with?("## ")
99
+ text = text.chomp("##").strip
100
+ normalized_lines << "#{indent}#{text}"
101
+ end
102
+
103
+ normalized_lines << "#{indent}#{BORDER_LINE}"
104
+ normalized_lines.join("\n")
105
+ end
106
+
107
+ def indentation(comment)
108
+ comment.text.match(/^\s*/)[0]
109
+ end
110
+
111
+ def range_for_block(block)
112
+ start_pos = block.first.location.expression.begin_pos
113
+ end_pos = block.last.location.expression.end_pos
114
+
115
+ Parser::Source::Range.new(processed_source.buffer, start_pos, end_pos)
116
+ end
117
+
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
@@ -2,6 +2,7 @@
2
2
  require:
3
3
  - rubocop/cop/style/method_call_with_args_parentheses_override
4
4
  - rubocop/cop/custom_cops/style/use_credentials_instead_of_env
5
+ - rubocop/cop/custom_cops/pre/comment_normalization
5
6
  AllCops:
6
7
  NewCops: enable
7
8
  EnabledByDefault: false
@@ -93,5 +94,7 @@ Style/MethodCallWithArgsParentheses:
93
94
  Enabled: true
94
95
  CustomCops/Style/UseCredentialsInsteadOfEnv:
95
96
  Enabled: true
97
+ CustomCops/Pre/CommentNormalization:
98
+ Enabled: true
96
99
  Gemspec/RequireMFA:
97
100
  Enabled: false
data/linters/rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  require:
2
2
  - rubocop/cop/style/method_call_with_args_parentheses_override
3
3
  - rubocop/cop/custom_cops/style/use_credentials_instead_of_env
4
+ - rubocop/cop/custom_cops/pre/comment_normalization
4
5
 
5
6
  # Pour activer toutes les méthodes de Rubocop et activer le cache pour les gros fichiers
6
7
  AllCops:
@@ -108,6 +109,8 @@ Style/MethodCallWithArgsParentheses:
108
109
  #################### CUSTOMS ###########################
109
110
  CustomCops/Style/UseCredentialsInsteadOfEnv:
110
111
  Enabled: true # On veut forcer l'utilisation de credentials au lieu de ENV pour les secrets
112
+ CustomCops/Pre/CommentNormalization:
113
+ Enabled: true # On veut forcer la normalisation des commentaires
111
114
 
112
115
  #################### GEM ###########################
113
116
  Gemspec/RequireMFA:
metadata CHANGED
@@ -1,103 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.53
4
+ version: 0.1.54
5
5
  platform: ruby
6
- original_platform: ''
7
6
  authors:
8
7
  - immosquare
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-20 00:00:00.000000000 Z
10
+ date: 2024-12-22 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: erb_lint
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.7'
19
+ - - "<="
18
20
  - !ruby/object:Gem::Version
19
- version: '0'
21
+ version: '1000.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: '0'
28
+ version: '0.7'
29
+ - - "<="
30
+ - !ruby/object:Gem::Version
31
+ version: '1000.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: htmlbeautifier
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - "~>"
36
+ - - ">="
32
37
  - !ruby/object:Gem::Version
33
- version: '1'
38
+ version: '1.4'
39
+ - - "<="
40
+ - !ruby/object:Gem::Version
41
+ version: '1000.0'
34
42
  type: :runtime
35
43
  prerelease: false
36
44
  version_requirements: !ruby/object:Gem::Requirement
37
45
  requirements:
38
- - - "~>"
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '1.4'
49
+ - - "<="
39
50
  - !ruby/object:Gem::Version
40
- version: '1'
51
+ version: '1000.0'
41
52
  - !ruby/object:Gem::Dependency
42
53
  name: immosquare-extensions
43
54
  requirement: !ruby/object:Gem::Requirement
44
55
  requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
56
  - - ">="
49
57
  - !ruby/object:Gem::Version
50
- version: 0.1.18
58
+ version: '0.1'
59
+ - - "<="
60
+ - !ruby/object:Gem::Version
61
+ version: '1000.0'
51
62
  type: :runtime
52
63
  prerelease: false
53
64
  version_requirements: !ruby/object:Gem::Requirement
54
65
  requirements:
55
- - - "~>"
56
- - !ruby/object:Gem::Version
57
- version: '0'
58
66
  - - ">="
59
67
  - !ruby/object:Gem::Version
60
- version: 0.1.18
68
+ version: '0.1'
69
+ - - "<="
70
+ - !ruby/object:Gem::Version
71
+ version: '1000.0'
61
72
  - !ruby/object:Gem::Dependency
62
73
  name: immosquare-yaml
63
74
  requirement: !ruby/object:Gem::Requirement
64
75
  requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
76
  - - ">="
69
77
  - !ruby/object:Gem::Version
70
- version: 0.1.26
78
+ version: '0.1'
79
+ - - "<="
80
+ - !ruby/object:Gem::Version
81
+ version: '1000.0'
71
82
  type: :runtime
72
83
  prerelease: false
73
84
  version_requirements: !ruby/object:Gem::Requirement
74
85
  requirements:
75
- - - "~>"
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
86
  - - ">="
79
87
  - !ruby/object:Gem::Version
80
- version: 0.1.26
88
+ version: '0.1'
89
+ - - "<="
90
+ - !ruby/object:Gem::Version
91
+ version: '1000.0'
81
92
  - !ruby/object:Gem::Dependency
82
93
  name: rubocop
83
94
  requirement: !ruby/object:Gem::Requirement
84
95
  requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '1'
88
96
  - - ">="
89
97
  - !ruby/object:Gem::Version
90
- version: 1.62.1
98
+ version: '1.68'
99
+ - - "<="
100
+ - !ruby/object:Gem::Version
101
+ version: '1000.0'
91
102
  type: :runtime
92
103
  prerelease: false
93
104
  version_requirements: !ruby/object:Gem::Requirement
94
105
  requirements:
95
- - - "~>"
96
- - !ruby/object:Gem::Version
97
- version: '1'
98
106
  - - ">="
99
107
  - !ruby/object:Gem::Version
100
- version: 1.62.1
108
+ version: '1.68'
109
+ - - "<="
110
+ - !ruby/object:Gem::Version
111
+ version: '1000.0'
101
112
  description: Immosquare-cleaner streamlines Rails applications by running tools like
102
113
  RuboCop, ERBLint, Stylelint and more. It ensures code quality, readability, and
103
114
  consistency across the application.
@@ -121,6 +132,7 @@ files:
121
132
  - linters/prettier.yml
122
133
  - linters/rubocop-3.3.6.yml
123
134
  - linters/rubocop.yml
135
+ - linters/rubocop/cop/custom_cops/pre/comment_normalization.rb
124
136
  - linters/rubocop/cop/custom_cops/style/use_credentials_instead_of_env.rb
125
137
  - linters/rubocop/cop/style/method_call_with_args_parentheses_override.rb
126
138
  - node_modules/.bin/acorn
@@ -34471,7 +34483,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
34471
34483
  requirements:
34472
34484
  - - ">="
34473
34485
  - !ruby/object:Gem::Version
34474
- version: 2.7.2
34486
+ version: 3.1.6
34475
34487
  required_rubygems_version: !ruby/object:Gem::Requirement
34476
34488
  requirements:
34477
34489
  - - ">="