Class: Suspenders::Generators::LintGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Suspenders::Generators::LintGenerator
show all
- Includes:
- Helpers
- Defined in:
- lib/generators/suspenders/lint_generator.rb
Instance Method Summary
collapse
Methods included from Helpers
#default_test_helper_present?, #default_test_suite?, #node_not_installed?, #node_version, #node_version_unsupported?, #rspec_test_helper_present?, #rspec_test_suite?
Instance Method Details
#check_package_json ⇒ Object
30
31
32
33
34
|
# File 'lib/generators/suspenders/lint_generator.rb', line 30
def check_package_json
unless File.exist? Rails.root.join("package.json")
copy_file "package.json", "package.json"
end
end
|
65
66
67
68
69
70
71
|
# File 'lib/generators/suspenders/lint_generator.rb', line 65
def configure_erb_lint
copy_file "erb-lint.yml", ".erb-lint.yml"
copy_file "config_better_html.yml", "config/better_html.yml"
copy_file "config_initializers_better_html.rb", "config/initializers/better_html.rb"
copy_file "erblint.rake", "lib/tasks/erblint.rake"
template "rubocop.yml.tt", ".rubocop.yml"
end
|
56
57
58
|
# File 'lib/generators/suspenders/lint_generator.rb', line 56
def configure_eslint
copy_file "eslintrc.json", ".eslintrc.json"
end
|
60
61
62
63
|
# File 'lib/generators/suspenders/lint_generator.rb', line 60
def configure_prettier
copy_file "prettierrc", ".prettierrc"
copy_file "prettierignore", ".prettierignore"
end
|
52
53
54
|
# File 'lib/generators/suspenders/lint_generator.rb', line 52
def configure_stylelint
copy_file "stylelintrc.json", ".stylelintrc.json"
end
|
#install_dependencies ⇒ Object
38
39
40
|
# File 'lib/generators/suspenders/lint_generator.rb', line 38
def install_dependencies
run "yarn add stylelint eslint@^8.9.0 @thoughtbot/stylelint-config @thoughtbot/eslint-config npm-run-all prettier --dev"
end
|
#install_gems ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/generators/suspenders/lint_generator.rb', line 42
def install_gems
gem_group :development, :test do
gem "better_html", require: false
gem "erb_lint", require: false
gem "erblint-github", require: false
gem "standard"
end
Bundler.with_unbundled_env { run "bundle install" }
end
|
#update_package_json ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/generators/suspenders/lint_generator.rb', line 73
def update_package_json
content = File.read package_json
json = JSON.parse content
json["scripts"] ||= {}
json["scripts"]["lint"] = "run-p lint:eslint lint:stylelint lint:prettier"
json["scripts"]["lint:eslint"] = "eslint --max-warnings=0 --no-error-on-unmatched-pattern 'app/javascript/**/*.js'"
json["scripts"]["lint:stylelint"] = "stylelint 'app/assets/stylesheets/**/*.css'"
json["scripts"]["lint:prettier"] = "prettier --check '**/*' --ignore-unknown"
json["scripts"]["fix:prettier"] = "prettier --write '**/*' --ignore-unknown"
File.write package_json, JSON.pretty_generate(json)
end
|