jslinting-rails 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/lib/install/eslint/eslint.config.mjs +9 -0
- data/lib/install/prettier/prettierrc.json +3 -0
- data/lib/install.rb +27 -0
- data/lib/jslinting/engine.rb +4 -0
- data/lib/jslinting/version.rb +3 -0
- data/lib/jslinting-rails.rb +21 -0
- data/lib/tasks/jslinting/install.rake +6 -0
- data/lib/tasks/jslinting/lint.rake +39 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2f8c0ce79c85ed178f30d654fe012f01b11b2fdedb62708567f0d2ccae7c25a
|
4
|
+
data.tar.gz: 17568f673307da1e2bee6e2c496f57bfcfe73d8d4361a6b84e801eade6ffeb70
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7f6ca972cf10d09a5ecdbcc602a61e16800cfa3fb4b15f26d0898d44ca172e075a98770eb8d229ea43c24fc19959de7f785f02b4ec4184b8ca0d24236276ff6
|
7
|
+
data.tar.gz: 57a3e30c1680b84f8f5c8c997475ef3d9fc77233a061f2ce571c61a6eaf0bd4b724867588523a861d4789a858ec1bbe2e636b6eaa32a6a3ee49e3e5cfa576fb2
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright Ethan Kircher
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# JavaScript Linting for Rails
|
2
|
+
|
3
|
+
This gem provides a basic eslint and prettier setup for Rails apps setup with [jsbundling-rails](https://github.com/rails/jsbundling-rails).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Ensure [jsbundling-rails](https://github.com/rails/jsbundling-rails) is installed in your application, as
|
8
|
+
`jslinting-rails` relies on it.
|
9
|
+
|
10
|
+
If you are using node, ensure npx >7.1 is installed.
|
11
|
+
|
12
|
+
If you are using bun, then you must have the bun runtime installed.
|
13
|
+
|
14
|
+
To get started run:
|
15
|
+
|
16
|
+
```bash
|
17
|
+
./bin/bundle add jslinting-rails --group development
|
18
|
+
```
|
19
|
+
|
20
|
+
```bash
|
21
|
+
./bin/rails jslinting:install
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
This gem adds two scripts to your `package.json`, `lint` and `format`.
|
27
|
+
|
28
|
+
They can be run directly through your package manager with
|
29
|
+
|
30
|
+
```bash
|
31
|
+
yarn run lint
|
32
|
+
yarn run format
|
33
|
+
```
|
34
|
+
|
35
|
+
or as a task via
|
36
|
+
|
37
|
+
```bash
|
38
|
+
rails javascript:lint
|
39
|
+
rails javascript:format
|
40
|
+
```
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
`jslinting-rails` is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/install.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
say "Install eslint and prettier"
|
2
|
+
run "#{Jslinting.package_manager} add -D eslint @eslint/js eslint globals prettier eslint-config-prettier"
|
3
|
+
|
4
|
+
say "Setup eslint"
|
5
|
+
copy_file "#{__dir__}/install/eslint/eslint.config.mjs", "eslint.config.mjs"
|
6
|
+
copy_file "#{__dir__}/install/prettier/prettierrc.json", ".prettierrc"
|
7
|
+
|
8
|
+
say "Add scripts"
|
9
|
+
lint_script = "eslint app/javascript --max-warnings 0 && prettier app/javascript --check"
|
10
|
+
format_script = "eslint app/javascript --fix && prettier app/javascript --write"
|
11
|
+
|
12
|
+
case `npx -v`.to_f
|
13
|
+
when 7.1...8.0
|
14
|
+
run %(npm set-script lint "#{lint_script}")
|
15
|
+
run %(npm set-script format "#{format_script}")
|
16
|
+
|
17
|
+
say "Formating..."
|
18
|
+
run "#{Jslinting.package_manager} run format"
|
19
|
+
when (8.0..)
|
20
|
+
run %(npm pkg set scripts.lint="#{lint_script}")
|
21
|
+
run %(npm pkg set scripts.format="#{format_script}")
|
22
|
+
|
23
|
+
say "Formating..."
|
24
|
+
run "#{Jslinting.package_manager} run format"
|
25
|
+
else
|
26
|
+
say %(Add "scripts": { "lint": "#{lint_script}", "format": "#{format_script}" } to your package.json), :green
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Jslinting
|
2
|
+
def self.package_manager
|
3
|
+
case
|
4
|
+
when File.exist?("bun.lockb") then :bun
|
5
|
+
when File.exist?("yarn.lock") then :yarn
|
6
|
+
when File.exist?("pnpm-lock.yaml") then :pnpm
|
7
|
+
when File.exist?("package-lock.json") then :npm
|
8
|
+
when pm_exists?("bun") then :bun
|
9
|
+
when pm_exists?("yarn") then :yarn
|
10
|
+
when pm_exists?("pnpm") then :pnpm
|
11
|
+
when pm_exists?("npm") then :npm
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.pm_exists?(pm)
|
16
|
+
system "which #{pm} > /dev/null"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require "jslinting/version"
|
21
|
+
require "jslinting/engine"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
namespace :javascript do
|
2
|
+
desc "Lint your JavaScript"
|
3
|
+
lint_task = task :lint do
|
4
|
+
command = Jslinting::Tasks.lint_command
|
5
|
+
unless system(command)
|
6
|
+
raise "jslinting-rails: Command lint failed, ensure `#{command}` runs without errors"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
lint_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
|
11
|
+
|
12
|
+
desc "Format your JavaScript"
|
13
|
+
format_task = task :format do
|
14
|
+
command = Jslinting::Tasks.lint_command
|
15
|
+
unless system(command)
|
16
|
+
raise "jslinting-rails: Command format failed, ensure `#{command}` runs without errors"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
format_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
|
21
|
+
end
|
22
|
+
|
23
|
+
module Jslinting
|
24
|
+
module Tasks
|
25
|
+
extend self
|
26
|
+
|
27
|
+
def lint_command
|
28
|
+
return "#{Jslinting.package_manager} run lint" if Jslinting.package_manager.present?
|
29
|
+
|
30
|
+
raise "jslinting-rails: No JavaScript package manager found"
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_command
|
34
|
+
return "#{Jslinting.package_manager} run format" if Jslinting.package_manager.present?
|
35
|
+
|
36
|
+
raise "jslinting-rails: No JavaScript package manager found"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jslinting-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ethan Kircher
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 6.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 6.0.0
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- ethanmichaelk@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- lib/install.rb
|
37
|
+
- lib/install/eslint/eslint.config.mjs
|
38
|
+
- lib/install/prettier/prettierrc.json
|
39
|
+
- lib/jslinting-rails.rb
|
40
|
+
- lib/jslinting/engine.rb
|
41
|
+
- lib/jslinting/version.rb
|
42
|
+
- lib/tasks/jslinting/install.rake
|
43
|
+
- lib/tasks/jslinting/lint.rake
|
44
|
+
homepage: https://github.com/rails/jsbundling-rails
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubygems_version: 3.5.9
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: Lint and format JavaScript in Rails with eslint and prettier
|
67
|
+
test_files: []
|