lib/immosquare-cleaner.rb in immosquare-cleaner-0.1.4 vs lib/immosquare-cleaner.rb in immosquare-cleaner-0.1.5
- old
+ new
@@ -1,6 +1,7 @@
-require "English"
+require "English"
+require "neatjson"
require_relative "immosquare-cleaner/configuration"
require_relative "immosquare-cleaner/railtie" if defined?(Rails)
##===========================================================================##
## Importing the 'English' library allows us to use more human-readable
@@ -53,9 +54,16 @@
cmd << [true, "bundle exec erblint --config #{gem_root}/linters/erb-lint.yml #{file_path} #{ImmosquareCleaner.configuration.erblint_options || "--autocorrect"}"]
elsif file_path.end_with?(".rb", ".rake", "Gemfile", "Rakefile", ".axlsx", ".gemspec", ".ru", ".podspec", ".jbuilder", ".rabl", ".thor", "config.ru", "Berksfile", "Capfile", "Guardfile", "Podfile", "Thorfile", "Vagrantfile") || File.open(file_path, &:gets)&.include?(SHEBANG)
cmd << [true, "bundle exec rubocop -c #{gem_root}/linters/rubocop.yml #{file_path} #{ImmosquareCleaner.configuration.rubocop_options || "--autocorrect-all"}"]
elsif file_path =~ %r{locales/.*\.yml$}
ImmosquareYaml.clean(file_path)
+ elsif file_path.end_with?(".js")
+ cmd << [false, "npx eslint --config #{gem_root}/linters/eslintrc.json #{file_path} --fix"]
+ elsif file_path.end_with?(".json")
+ json_str = File.read(file_path)
+ parsed_data = JSON.parse(json_str)
+ formated = JSON.neat_generate(parsed_data, :aligned => true)
+ File.write(file_path, formated)
elsif npx_installed? && prettier_installed?
prettier_parser = nil
prettier_parser = "--parser markdown" if file_path.end_with?(".md.erb")
cmd << [false, "npx prettier --write #{file_path} #{prettier_parser} --config #{gem_root}/linters/prettier.yml"]
else