eslint-changes 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.rubocop.yml +27 -0
- data/.semgrep.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +41 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/eslint-changes.gemspec +46 -0
- data/exe/eslint-changes +16 -0
- data/lib/eslint/changes/check.rb +42 -0
- data/lib/eslint/changes/checker.rb +126 -0
- data/lib/eslint/changes/options.rb +80 -0
- data/lib/eslint/changes/shell.rb +11 -0
- data/lib/eslint/changes/version.rb +7 -0
- data/lib/eslint/changes.rb +8 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1bdae13b94a3db4040118985e40f866348ab4773cb664adeb9051b000b6d3631
|
4
|
+
data.tar.gz: 40f13cbda38ef96c49b322dc3c2a51156f65a6c8bf79031414c07c853f1beed0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 862c9940f0b0220303a536c46cb36abcfc9c97feb421f04d741a3dbaa8f09ca157d58151f81a82c3780f0fa6345a50357f7ef66612a71be800625ee88dad258d
|
7
|
+
data.tar.gz: db3d31a061af1a0647703452fd3c9c18632f43739f0469b06310dee028c6f496103f63ac277fd84447801654316382370638205c4210cbdd950709cc0e3875e3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5
|
3
|
+
NewCops: disable
|
4
|
+
|
5
|
+
Lint/RaiseException:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Lint/StructNewOverride:
|
9
|
+
Enabled: false
|
10
|
+
|
11
|
+
Style/HashEachMethods:
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Style/HashTransformKeys:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Style/HashTransformValues:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Style/FrozenStringLiteralComment:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Layout/LineLength:
|
27
|
+
Max: 120
|
data/.semgrep.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at fcsonline@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
eslint-changes (0.1.0)
|
5
|
+
colorize (~> 0.8.1)
|
6
|
+
git_diff_parser (~> 3.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
byebug (10.0.2)
|
12
|
+
colorize (0.8.1)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
git_diff_parser (3.2.0)
|
15
|
+
rake (13.0.3)
|
16
|
+
rspec (3.9.0)
|
17
|
+
rspec-core (~> 3.9.0)
|
18
|
+
rspec-expectations (~> 3.9.0)
|
19
|
+
rspec-mocks (~> 3.9.0)
|
20
|
+
rspec-core (3.9.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-expectations (3.9.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-mocks (3.9.0)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.9.0)
|
28
|
+
rspec-support (3.9.0)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 2.0)
|
35
|
+
byebug (~> 10.0)
|
36
|
+
eslint-changes!
|
37
|
+
rake (~> 13.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
|
40
|
+
BUNDLED WITH
|
41
|
+
2.3.12
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Ferran Basora
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Ferran Basora
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Eslint::Changes
|
2
|
+
|
3
|
+
[![Gem Version](https://img.shields.io/gem/v/eslint-changes)](https://rubygems.org/gems/eslint-changes)
|
4
|
+
[![Build Status](https://github.com/fcsonline/eslint-changes/actions/workflows/ci.yml/badge.svg)](https://github.com/fcsonline/eslint-changes/actions/workflows/ci.yml)
|
5
|
+
|
6
|
+
`eslint-changes` shows only the offenses you introduced since the fork point
|
7
|
+
of your git branch. Will not complain about existing offenses in your main
|
8
|
+
branch.
|
9
|
+
|
10
|
+
This is useful for CI checks for your pull requests but it could be useful too
|
11
|
+
for you daily work, to know new offenses created by you.
|
12
|
+
|
13
|
+
Internally `eslint-changes` reads the `json` output from `eslint` and a `git
|
14
|
+
diff` and does the intersection of line numbers to know the new offenses you
|
15
|
+
are introducing to you main branch.
|
16
|
+
|
17
|
+
## Installation
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
gem 'eslint-changes'
|
23
|
+
```
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install eslint-changes
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
$ bundle exec eslint-changes
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fcsonline/eslint-changes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the Eslint::Changes project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fcsonline/eslint-changes/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'eslint/changes'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'eslint/changes/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'eslint-changes'
|
7
|
+
spec.version = Eslint::Changes::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.required_ruby_version = '>= 2.5.0'
|
10
|
+
spec.authors = ['Ferran Basora']
|
11
|
+
spec.email = ['fcsonline@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Eslint on changed lines from git fork point'
|
14
|
+
spec.description = <<-DESCRIPTION
|
15
|
+
eslint-changes will run eslint on changed lines from forked point in your main branch.
|
16
|
+
It will not complain about existing offenses in master branch on your git prioject.
|
17
|
+
This gem is perfect as a Continuous Integration tool
|
18
|
+
DESCRIPTION
|
19
|
+
|
20
|
+
spec.homepage = 'https://rubygems.org/gems/eslint-changes'
|
21
|
+
spec.license = 'MIT'
|
22
|
+
|
23
|
+
spec.metadata = {
|
24
|
+
'source_code_uri' => 'https://github.com/fcsonline/eslint-changes',
|
25
|
+
'bug_tracker_uri' => 'https://github.com/fcsonline/eslint-changes/issues'
|
26
|
+
}
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
30
|
+
# into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = 'exe'
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.extra_rdoc_files = ['LICENSE.txt', 'README.md']
|
37
|
+
spec.require_paths = ['lib']
|
38
|
+
|
39
|
+
spec.add_runtime_dependency 'git_diff_parser', '~> 3.2'
|
40
|
+
spec.add_runtime_dependency 'colorize', '~> 0.8.1'
|
41
|
+
|
42
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
43
|
+
spec.add_development_dependency 'byebug', '~> 10.0'
|
44
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
45
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
46
|
+
end
|
data/exe/eslint-changes
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'eslint/changes/checker'
|
5
|
+
require 'eslint/changes/options'
|
6
|
+
|
7
|
+
args = Eslint::Changes::Options.new.parse!
|
8
|
+
|
9
|
+
offenses = Eslint::Changes::Checker.new(
|
10
|
+
report: args.report,
|
11
|
+
quiet: args.quiet,
|
12
|
+
commit: args.commit,
|
13
|
+
base_branch: args.base_branch
|
14
|
+
).run
|
15
|
+
|
16
|
+
exit offenses.positive? ? 1 : 0
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Eslint
|
4
|
+
module Changes
|
5
|
+
class Check
|
6
|
+
def initialize(path, analysis, patch)
|
7
|
+
@path = path
|
8
|
+
@analysis = analysis
|
9
|
+
@patch = patch
|
10
|
+
end
|
11
|
+
|
12
|
+
def offenses
|
13
|
+
analysis.messages.select do |offense|
|
14
|
+
line_numbers.include?(line(offense))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :path, :analysis, :patch
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def line_numbers
|
23
|
+
@line_numbers ||= lines_from_diff & lines_from_eslint
|
24
|
+
end
|
25
|
+
|
26
|
+
def lines_from_diff
|
27
|
+
patch.changed_line_numbers
|
28
|
+
end
|
29
|
+
|
30
|
+
def lines_from_eslint
|
31
|
+
analysis
|
32
|
+
.messages
|
33
|
+
.map(&method(:line)) # Change me
|
34
|
+
.uniq
|
35
|
+
end
|
36
|
+
|
37
|
+
def line(offense)
|
38
|
+
offense.line
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'git_diff_parser'
|
4
|
+
require 'json'
|
5
|
+
require 'colorize'
|
6
|
+
|
7
|
+
require 'eslint/changes/check'
|
8
|
+
require 'eslint/changes/shell'
|
9
|
+
|
10
|
+
module Eslint
|
11
|
+
module Changes
|
12
|
+
class UnknownForkPointError < StandardError; end
|
13
|
+
|
14
|
+
class Checker
|
15
|
+
def initialize(report:, quiet:, commit:, base_branch:)
|
16
|
+
@report = report
|
17
|
+
@quiet = quiet
|
18
|
+
@commit = commit
|
19
|
+
@base_branch = base_branch
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
raise UnknownForkPointError if fork_point.empty?
|
24
|
+
|
25
|
+
print_offenses! unless quiet
|
26
|
+
|
27
|
+
total_offenses
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :report, :format, :quiet, :commit
|
33
|
+
|
34
|
+
def fork_point
|
35
|
+
@fork_point ||= Shell.run(command)
|
36
|
+
end
|
37
|
+
|
38
|
+
def command
|
39
|
+
return "git merge-base HEAD origin/#{@base_branch}" unless commit
|
40
|
+
|
41
|
+
"git log -n 1 --pretty=format:\"%h\" #{commit}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def diff
|
45
|
+
Shell.run("git diff #{fork_point}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def patches
|
49
|
+
@patches ||= GitDiffParser.parse(diff)
|
50
|
+
end
|
51
|
+
|
52
|
+
def changed_files
|
53
|
+
patches.map(&:file)
|
54
|
+
end
|
55
|
+
|
56
|
+
def eslint_json
|
57
|
+
@eslint_json ||= JSON.parse(File.read(report), object_class: OpenStruct)
|
58
|
+
end
|
59
|
+
|
60
|
+
def checks
|
61
|
+
@checks ||= changed_files.map do |file|
|
62
|
+
analysis = eslint_json.find { |item| item.filePath.end_with?(file) }
|
63
|
+
patch = patches.find { |item| item.file == file }
|
64
|
+
|
65
|
+
next unless analysis
|
66
|
+
|
67
|
+
Check.new(analysis.filePath, analysis, patch)
|
68
|
+
end.compact
|
69
|
+
end
|
70
|
+
|
71
|
+
def total_offenses
|
72
|
+
total_error_offenses
|
73
|
+
end
|
74
|
+
|
75
|
+
def total_error_offenses
|
76
|
+
checks.map do |check|
|
77
|
+
check.offenses.filter do |offense|
|
78
|
+
offense.severity == 2
|
79
|
+
end.size
|
80
|
+
end.inject(0, :+)
|
81
|
+
end
|
82
|
+
|
83
|
+
def total_warn_offenses
|
84
|
+
checks.map do |check|
|
85
|
+
check.offenses.filter do |offense|
|
86
|
+
offense.severity == 1
|
87
|
+
end.size
|
88
|
+
end.inject(0, :+)
|
89
|
+
end
|
90
|
+
|
91
|
+
def print_offenses!
|
92
|
+
msg ""
|
93
|
+
|
94
|
+
checks.each do |check|
|
95
|
+
print_offenses_for_check(check)
|
96
|
+
end
|
97
|
+
|
98
|
+
msg ""
|
99
|
+
msg "✖ #{total_error_offenses + total_warn_offenses} problems (#{total_error_offenses} error, #{total_warn_offenses} warnings)".red.bold
|
100
|
+
end
|
101
|
+
|
102
|
+
def print_offenses_for_check(check)
|
103
|
+
return unless check.offenses.length > 0
|
104
|
+
|
105
|
+
msg "#{check.path.underline}"
|
106
|
+
check.offenses.map do |offense|
|
107
|
+
place = "#{offense.line}:#{offense.column}".light_black
|
108
|
+
msg " #{place} #{severity(offense.severity)} #{offense.message} #{offense.ruleId.light_black}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def severity(value)
|
113
|
+
return 'error'.red if value == 2
|
114
|
+
return 'warn'.yellow if value == 1
|
115
|
+
|
116
|
+
'off'
|
117
|
+
end
|
118
|
+
|
119
|
+
def msg(message)
|
120
|
+
return if ENV['RACK_ENV'] == 'test'
|
121
|
+
|
122
|
+
puts message
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module Eslint
|
6
|
+
module Changes
|
7
|
+
class Options
|
8
|
+
Options = Struct.new(:report, :quiet, :commit, :base_branch)
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@args = Options.new(nil, false, nil, 'main') # Defaults
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse!
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.banner = 'Usage: eslint-changes [options]'
|
17
|
+
|
18
|
+
parse_report!(opts)
|
19
|
+
parse_commit!(opts)
|
20
|
+
parse_quiet!(opts)
|
21
|
+
parse_help!(opts)
|
22
|
+
parse_version!(opts)
|
23
|
+
parse_base_branch!(opts)
|
24
|
+
end.parse!
|
25
|
+
|
26
|
+
args
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
attr_reader :args
|
32
|
+
|
33
|
+
def parse_report!(opts)
|
34
|
+
opts.on(
|
35
|
+
'-r',
|
36
|
+
'--report [REPORT]',
|
37
|
+
"Specify the eslint report in json format"
|
38
|
+
) do |r|
|
39
|
+
args.report = r
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_commit!(opts)
|
44
|
+
opts.on(
|
45
|
+
'-c',
|
46
|
+
'--commit [COMMIT_ID]',
|
47
|
+
'Compare from some specific point on git history'
|
48
|
+
) do |c|
|
49
|
+
args.commit = c
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def parse_quiet!(opts)
|
54
|
+
opts.on('-q', '--quiet', 'Be quiet') do |v|
|
55
|
+
args.quiet = v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def parse_base_branch!(opts)
|
60
|
+
opts.on('-b', '--base_branch [BRANCH]', 'Base branch to compare') do |v|
|
61
|
+
args.base_branch = v
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def parse_help!(opts)
|
66
|
+
opts.on('-h', '--help', 'Prints this help') do
|
67
|
+
puts opts
|
68
|
+
exit
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def parse_version!(opts)
|
73
|
+
opts.on('--version', 'Display version') do
|
74
|
+
puts Eslint::Changes::VERSION
|
75
|
+
exit 0
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eslint-changes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ferran Basora
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git_diff_parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: |2
|
98
|
+
eslint-changes will run eslint on changed lines from forked point in your main branch.
|
99
|
+
It will not complain about existing offenses in master branch on your git prioject.
|
100
|
+
This gem is perfect as a Continuous Integration tool
|
101
|
+
email:
|
102
|
+
- fcsonline@gmail.com
|
103
|
+
executables:
|
104
|
+
- eslint-changes
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- ".rspec"
|
112
|
+
- ".rubocop.yml"
|
113
|
+
- ".semgrep.yml"
|
114
|
+
- CODE_OF_CONDUCT.md
|
115
|
+
- Gemfile
|
116
|
+
- Gemfile.lock
|
117
|
+
- LICENSE
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- Rakefile
|
121
|
+
- bin/console
|
122
|
+
- bin/setup
|
123
|
+
- eslint-changes.gemspec
|
124
|
+
- exe/eslint-changes
|
125
|
+
- lib/eslint/changes.rb
|
126
|
+
- lib/eslint/changes/check.rb
|
127
|
+
- lib/eslint/changes/checker.rb
|
128
|
+
- lib/eslint/changes/options.rb
|
129
|
+
- lib/eslint/changes/shell.rb
|
130
|
+
- lib/eslint/changes/version.rb
|
131
|
+
homepage: https://rubygems.org/gems/eslint-changes
|
132
|
+
licenses:
|
133
|
+
- MIT
|
134
|
+
metadata:
|
135
|
+
source_code_uri: https://github.com/fcsonline/eslint-changes
|
136
|
+
bug_tracker_uri: https://github.com/fcsonline/eslint-changes/issues
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 2.5.0
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubygems_version: 3.3.5
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Eslint on changed lines from git fork point
|
156
|
+
test_files: []
|