immosquare-cleaner 0.1.7 → 0.1.8

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: fda22c4cddfb38be76c1c0d7bd063588f229ca8f6b07758d885c3e84c170828f
4
- data.tar.gz: '09da73ea818492ab6c6ce129d96ce3838a11d404c23e5a7b3b41ec271024d266'
3
+ metadata.gz: ec2041334b9098e1f6b501cdeb0155fac6bf061ac20e77102e9a36c72065e298
4
+ data.tar.gz: 4a7d25d7ca56b906cec3013e8aa383bb7edcd56e88123f0baf50169f1b9a678a
5
5
  SHA512:
6
- metadata.gz: 5daaff785cb3b11f5a3ddaa386ef1356ab9b03043a0e1d73b85076fc806b4caaa1b852d774a7e3c983897db5f5237e050ba1d4540ba78f4902dfd0a777e8237c
7
- data.tar.gz: 139109ccee0b310f213065fb253c3c0873e4b4ae220ac0d4b0bab0b6ee0183864d5fa01bcf0671705a48bd0509a13a5af69fbfbe19ca84adf89467b4c051f6ec
6
+ metadata.gz: 695a74e0a92e19fe5a51e1d283786df24d722412ca6d2dbcc097480fe52dce674b97d44f18e5acccb4c2f5c9ee170cc5e3bae91cbd76b97719f00958b233a19c
7
+ data.tar.gz: 9833e7b8bb962471c72ffe624a5ec900422498990cb2f890630ae74f626b5f90cfdc389c0d5b827c01eb7ba98733e6f5faa807e4c44ae38222ae44feeb61648b
@@ -1,8 +1,22 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "immosquare_cleaner"
3
+ require "immosquare-cleaner"
4
4
  require "optparse"
5
5
 
6
+
7
+ ##===========================================================================##
8
+ ## We check if bun.sh is installed
9
+ ##===========================================================================##
10
+ def bun_installed?
11
+ system("which bun > /dev/null 2>&1")
12
+ end
13
+
14
+ if !bun_installed?
15
+ puts "Error: 'bun' is not installed. Please install it first.(https://bun.sh/)"
16
+ exit(1)
17
+ end
18
+
19
+
6
20
  options = {}
7
21
  ##===========================================================================##
8
22
  ## optparse is a standard library of ruby, it's used to parse command line ##
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.7".freeze
2
+ VERSION = "0.1.8".freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  require "English"
2
2
  require "neatjson"
3
- require_relative "immosquare_cleaner/configuration"
4
- require_relative "immosquare_cleaner/railtie" if defined?(Rails)
3
+ require_relative "immosquare-cleaner/configuration"
4
+ require_relative "immosquare-cleaner/railtie" if defined?(Rails)
5
5
 
6
6
  ##===========================================================================##
7
7
  ## Importing the 'English' library allows us to use more human-readable
@@ -35,82 +35,67 @@ module ImmosquareCleaner
35
35
  ##============================================================##
36
36
  ## Default options
37
37
  ##============================================================##
38
- procesed = false
39
- cmd = []
40
- options = {}.merge(options)
41
-
38
+ options = {}.merge(options)
42
39
 
43
40
  begin
44
- raise("Error: The file '#{file_path}' does not exist.") if !File.exist?(file_path)
45
-
46
41
  ##============================================================##
47
42
  ## .html.erb files
48
43
  ##============================================================##
49
44
  if file_path.end_with?(".html.erb")
50
- cmd << "bundle exec htmlbeautifier #{file_path} #{ImmosquareCleaner.configuration.htmlbeautifier_options || "--keep-blank-lines 4"}"
51
- cmd << "bundle exec erblint --config #{gem_root}/linters/erb-lint.yml #{file_path} #{ImmosquareCleaner.configuration.erblint_options || "--autocorrect"}"
52
- procesed = true
45
+ cmds = []
46
+ cmds << "bundle exec htmlbeautifier #{file_path} #{ImmosquareCleaner.configuration.htmlbeautifier_options || "--keep-blank-lines 4"}"
47
+ cmds << "bundle exec erblint --config #{gem_root}/linters/erb-lint.yml #{file_path} #{ImmosquareCleaner.configuration.erblint_options || "--autocorrect"}"
48
+ launch_cmds(cmds)
49
+ normalize_last_line(file_path)
50
+ return
53
51
  end
54
52
 
55
53
  ##============================================================##
56
54
  ## Ruby Files
57
55
  ##============================================================##
58
- if !procesed && (file_path.end_with?(*RUBY_FILES) || File.open(file_path, &:gets)&.include?(SHEBANG))
59
- cmd << "bundle exec rubocop -c #{gem_root}/linters/rubocop.yml #{file_path} #{ImmosquareCleaner.configuration.rubocop_options || "--autocorrect-all"}"
60
- procesed = true
56
+ if file_path.end_with?(*RUBY_FILES) || File.open(file_path, &:gets)&.include?(SHEBANG)
57
+ cmds = ["bundle exec rubocop -c #{gem_root}/linters/rubocop.yml #{file_path} #{ImmosquareCleaner.configuration.rubocop_options || "--autocorrect-all"}"]
58
+ launch_cmds(cmds)
59
+ normalize_last_line(file_path)
60
+ return
61
61
  end
62
62
 
63
63
  ##============================================================##
64
64
  ## Yml translations files
65
65
  ##============================================================##
66
- if !procesed && file_path =~ %r{locales/.*\.yml$}
66
+ if file_path =~ %r{locales/.*\.yml$}
67
67
  ImmosquareYaml.clean(file_path)
68
- procesed = true
68
+ return
69
69
  end
70
70
 
71
71
  ##============================================================##
72
72
  ## JS files
73
73
  ##============================================================##
74
- if !procesed && file_path.end_with?(".js")
75
- cmd << "npx eslint --config #{gem_root}/linters/eslintrc.json #{file_path} --fix"
76
- procesed = true
74
+ if file_path.end_with?(".js")
75
+ cmds = ["bun eslint --config #{gem_root}/linters/eslintrc.json #{file_path} --fix"]
76
+ launch_cmds(cmds)
77
+ normalize_last_line(file_path)
78
+ return
77
79
  end
78
80
 
79
81
  ##============================================================##
80
82
  ## JSON files
81
83
  ##============================================================##
82
- if !procesed && file_path.end_with?(".json")
84
+ if file_path.end_with?(".json")
83
85
  json_str = File.read(file_path)
84
86
  parsed_data = JSON.parse(json_str)
85
87
  formated = JSON.neat_generate(parsed_data, :aligned => true)
86
88
  File.write(file_path, formated)
87
- procesed = true
89
+ normalize_last_line(file_path)
90
+ return
88
91
  end
89
92
 
90
93
  ##============================================================##
91
94
  ## Autres formats
92
95
  ##============================================================##
93
- if npx_installed? && prettier_installed?
94
- prettier_parser = nil
95
- prettier_parser = "--parser markdown" if file_path.end_with?(".md.erb")
96
- cmd << "npx prettier --write #{file_path} #{prettier_parser} --config #{gem_root}/linters/prettier.yml"
97
- else
98
- puts("Warning: npx and/or prettier are not installed. Skipping formatting.")
99
- end if !procesed
100
-
101
-
102
- ##===========================================================================##
103
- ## We change the current directory to the gem root to ensure the gem's paths
104
- ## are used when executing the commands
105
- ##===========================================================================##
106
- Dir.chdir(gem_root) do
107
- cmd.each {|c| system(c) }
108
- end if !cmd.empty?
109
-
110
- ##============================================================##
111
- ## We normalize the last line of the file to ensure it ends with a single
112
- ##============================================================##
113
- normalize_last_line(file_path)
96
+ prettier_parser = nil
97
+ prettier_parser = "--parser markdown" if file_path.end_with?(".md.erb")
98
+ cmds = "bun prettier --write #{file_path} #{prettier_parser} --config #{gem_root}/linters/prettier.yml"
114
99
  rescue StandardError => e
115
100
  puts(e.message)
116
101
  puts(e.backtrace)
@@ -124,12 +109,14 @@ module ImmosquareCleaner
124
109
  File.expand_path("..", __dir__)
125
110
  end
126
111
 
127
- def npx_installed?
128
- system("which npx > /dev/null 2>&1")
129
- end
130
-
131
- def prettier_installed?
132
- system("npx prettier --version > /dev/null 2>&1")
112
+ ##===========================================================================##
113
+ ## We change the current directory to the gem root to ensure the gem's paths
114
+ ## are used when executing the commands
115
+ ##===========================================================================##
116
+ def launch_cmds(cmds)
117
+ Dir.chdir(gem_root) do
118
+ cmds.each {|cmd| system(cmd) }
119
+ end
133
120
  end
134
121
 
135
122
  ##===========================================================================##
@@ -1,36 +1,30 @@
1
1
  {
2
- "env": {
3
- "browser": true,
4
- "es2021": true
5
- },
6
- "ignorePatterns": ["package.json"],
7
- "extends": ["airbnb-base", "plugin:jsonc/recommended-with-jsonc"],
8
- "overrides": [],
9
- "parserOptions": {
10
- "ecmaVersion": "latest",
11
- "sourceType": "module"
12
- },
13
- "rules": {
14
- "quotes": [2, "double"],
15
- "semi": [2, "never"],
16
- "camelcase": 0,
17
- "no-console": 0,
18
- "no-restricted-globals": 0,
19
- "no-multi-spaces": 0,
20
- "no-undef": 0,
21
- "radix": 0,
22
- "key-spacing": [2, { "align": "value" }],
23
- "max-len": 0,
24
- "no-unused-expressions": 0,
25
- "padded-blocks": 0,
26
- "no-multiple-empty-lines": 0,
27
- "default-case": 0,
28
- "no-alert": 0,
29
- "no-lonely-if": 0,
30
- "no-nested-ternary": 0,
31
- "no-param-reassign": ["error", { "props": false }],
32
- "comma-dangle": ["error", "never"],
33
- "jsonc/auto": 2,
34
- "jsonc/indent": ["error", 2, {}]
2
+ "env" :{"browser":true,"es2021":true},
3
+ "ignorePatterns":["package.json"],
4
+ "extends" :["airbnb-base","plugin:jsonc/recommended-with-jsonc"],
5
+ "overrides" :[],
6
+ "parserOptions" :{"ecmaVersion":"latest","sourceType":"module"},
7
+ "rules" :{
8
+ "quotes" :[2,"double"],
9
+ "semi" :[2,"never"],
10
+ "camelcase" :0,
11
+ "no-console" :0,
12
+ "no-restricted-globals" :0,
13
+ "no-multi-spaces" :0,
14
+ "no-undef" :0,
15
+ "radix" :0,
16
+ "key-spacing" :[2,{"align":"value"}],
17
+ "max-len" :0,
18
+ "no-unused-expressions" :0,
19
+ "padded-blocks" :0,
20
+ "no-multiple-empty-lines":0,
21
+ "default-case" :0,
22
+ "no-alert" :0,
23
+ "no-lonely-if" :0,
24
+ "no-nested-ternary" :0,
25
+ "no-param-reassign" :["error",{"props":false}],
26
+ "comma-dangle" :["error","never"],
27
+ "jsonc/auto" :2,
28
+ "jsonc/indent" :["error",2,{}]
35
29
  }
36
30
  }
data/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
- "name" :"immosquare-cleaner",
3
- "private" :true,
4
- "dependencies" :{"eslint":"^8.50.0","prettier":"^3.0.3"},
5
- "devDependencies":{
2
+ "name" :"immosquare-cleaner",
3
+ "private" :true,
4
+ "dependencies":{
5
+ "eslint" :"^8.50.0",
6
+ "prettier" :"^3.0.3",
6
7
  "eslint-config-airbnb-base":"^15.0.0",
7
8
  "eslint-plugin-import" :"^2.28.1",
8
9
  "eslint-plugin-jsonc" :"^2.9.0"
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.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - IMMO SQUARE
@@ -77,10 +77,10 @@ extensions: []
77
77
  extra_rdoc_files: []
78
78
  files:
79
79
  - bin/immosquare-cleaner
80
- - lib/immosquare_cleaner.rb
81
- - lib/immosquare_cleaner/configuration.rb
82
- - lib/immosquare_cleaner/railtie.rb
83
- - lib/immosquare_cleaner/version.rb
80
+ - lib/immosquare-cleaner.rb
81
+ - lib/immosquare-cleaner/configuration.rb
82
+ - lib/immosquare-cleaner/railtie.rb
83
+ - lib/immosquare-cleaner/version.rb
84
84
  - lib/tasks/immosquare_cleaner.rake
85
85
  - linters/erb-lint.yml
86
86
  - linters/eslintrc.json