gl_lint 0.2.1 → 0.3.1

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: 29ba9f97248e034bfecc67d5fdc9fd0499abf4f1643ca3bed324429d3822dea5
4
- data.tar.gz: 37ca5350b17ab1efe805792b593c17a214eb3431b9c2e21ce9ab597434eb35b8
3
+ metadata.gz: 8c1993de87cae11e8c78789a86dd76ee188cd31981d236a28c133b52504abbe9
4
+ data.tar.gz: b9ad1954c44aca7f018a2421e5bcae5d1f52985fca5d317a010f3703ad00d8fa
5
5
  SHA512:
6
- metadata.gz: dc50f8bedbd5c87cf364b2af96fbf977bdb0ce454cb74fec6f29818f60d0b4baf8aa4d5168dda72656c20d83c743d8292b35224bf7ed802edf31e6379a16e4c8
7
- data.tar.gz: e18e12bb3ed9eb52787966ddba7099a580bc57116cef209e360a742df3a55b706758681fd24c9b7f95a0d84a5ef803321e704a29834df7571653b951178aa243
6
+ metadata.gz: 38a4162f951fbd544db9bf19e8d695d59c1be219a46d293beca1a39fc229e62f758ee69cf621f2d6a500c6589fe80fa605505c76c8ec63f4a886f2e706e2c12d
7
+ data.tar.gz: ee5565380924ff2faeddfd96e4d4ea823ec1988321597aeb426fbe21eb87bf5b67e9a83e3c048c3f8444d19fde3f5f72666f32340dd5d859ca18064121f456ff
data/README.md CHANGED
@@ -31,7 +31,7 @@ Then add this to the file:
31
31
  require 'rubygems'
32
32
  require 'gl_lint'
33
33
 
34
- GlLint.run_cli(app_root: File.expand_path('..', __dir__))
34
+ GlLint.call_cli(app_root: File.expand_path('..', __dir__))
35
35
  ```
36
36
 
37
37
  Then run `bin/lint` to lint your changes
@@ -39,16 +39,6 @@ Then run `bin/lint` to lint your changes
39
39
  Alternatively, if your project doesn't have JavaScript, add `linters: ['rubocop]`
40
40
 
41
41
  ```ruby
42
- GlLint.run_cli(app_root: File.expand_path('..', __dir__),
42
+ GlLint.call_cli(app_root: File.expand_path('..', __dir__),
43
43
  linters: ['rubocop'])
44
44
  ```
45
-
46
- ## Publishing gem to rubygems!
47
-
48
- [Build the gem](http://guides.rubygems.org/make-your-own-gem/)
49
-
50
- gem build gl_lint.gemspec
51
-
52
- [Push to rubygems](http://guides.rubygems.org/publishing/)
53
-
54
- gem push gl_lint-0.2.0.gem
data/gl_lint.gemspec CHANGED
@@ -5,6 +5,8 @@ lib = File.expand_path('lib', __dir__)
5
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
6
  require 'gl_lint/version'
7
7
 
8
+ NON_GEM_FILES = ['Gemfile', 'Gemfile.lock', 'Guardfile', 'bin/lint'].freeze
9
+
8
10
  Gem::Specification.new do |spec|
9
11
  spec.name = 'gl_lint'
10
12
  spec.version = GlLint::VERSION
@@ -18,7 +20,8 @@ Gem::Specification.new do |spec|
18
20
 
19
21
  spec.extra_rdoc_files = ['README.md']
20
22
 
21
- spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR).grep_v(/^(spec|\.)/)
23
+ spec.files = `git ls-files`
24
+ .split($INPUT_RECORD_SEPARATOR).grep_v(/^(spec|\.)/) - NON_GEM_FILES
22
25
  spec.require_paths = ['lib']
23
26
 
24
27
  spec.add_dependency 'optparse'
data/lib/gl_lint/cli.rb CHANGED
@@ -15,9 +15,8 @@ module GlLint
15
15
  class << self
16
16
  # Disabling metrics, it doesn't make sense to deconstruct the CLI parser
17
17
  # rubocop:disable Metrics
18
- def parse(app_root:, linters: nil, default_target: nil)
19
- options = lint_options(linters:, default_target:)
20
- .merge(app_root:)
18
+ def parse(app_root:, linters: nil, default_target: nil, options: {})
19
+ options = default_options(linters:, app_root:, default_target:).merge(options)
21
20
 
22
21
  OptionParser.new do |parser|
23
22
  TARGET_FILE_OPTS.each do |args|
@@ -80,7 +79,6 @@ module GlLint
80
79
 
81
80
  raise "Passed both 'filenames' and 'target files': #{options[:target_files]}" if options[:target_files]
82
81
  end
83
-
84
82
  options[:target_files] ||= options[:default_target]
85
83
  options
86
84
  end
@@ -88,11 +86,17 @@ module GlLint
88
86
 
89
87
  private
90
88
 
91
- def lint_options(linters:, default_target: nil)
89
+ def default_options(linters:, app_root:, default_target:)
92
90
  {
93
- linters: linters || LINTERS,
91
+ app_root:,
92
+ default_target: default_target || DEFAULT_TARGET,
93
+ filenames: nil,
94
+ linters: Array(linters || LINTERS),
95
+ list_only: false,
96
+ no_fix: false,
94
97
  unsafe_fix: ENV['UNSAFE_LINT'] == 'true',
95
- default_target: default_target || DEFAULT_TARGET
98
+ verbose: false,
99
+ write_rubocop_rules: false
96
100
  }
97
101
  end
98
102
  end
@@ -9,7 +9,8 @@ module GlLint
9
9
  def write_rules(app_root)
10
10
  puts 'Updating .rubocop_rules.yml'
11
11
 
12
- enabled_rules = rubocop_rules.map { |arr| stored_rule(app_root, arr) }.compact
12
+ enabled_rules = [['RuboCop-version', rubocop_version]] +
13
+ rubocop_rules.map { |arr| stored_rule(app_root, arr) }.compact
13
14
 
14
15
  File.write('.rubocop_rules.yml', YAML.dump(enabled_rules.to_h))
15
16
  end
@@ -32,6 +33,10 @@ module GlLint
32
33
  YAML.safe_load(`rubocop -c .rubocop.yml --show-cops`,
33
34
  permitted_classes: [Regexp, Symbol]).to_a
34
35
  end
36
+
37
+ def rubocop_version
38
+ `rubocop -V`.strip.split("\n").first.split('[').first.strip
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GlLint
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.1'
5
5
  end
data/lib/gl_lint.rb CHANGED
@@ -5,28 +5,33 @@ require 'gl_lint/export_rubocop'
5
5
 
6
6
  module GlLint
7
7
  class << self
8
- def lint_strategy_from_options(no_fix: false, list_only: false, unsafe_fix: false)
9
- return :list_only if list_only
10
- return :no_fix if no_fix
8
+ def call_cli(app_root:, default_target: nil, linters: nil)
9
+ options = GlLint::CLI.parse(app_root:, linters:, default_target:)
10
+ puts 'Options: ', options, '' if options[:verbose]
11
11
 
12
- unsafe_fix ? :unsafe_fix : :fix
12
+ call(**options.except(:verbose, :default_target))
13
13
  end
14
14
 
15
- def run_cli(app_root:, linters: nil)
16
- options = GlLint::CLI.parse(app_root:, linters:)
17
- puts 'Options: ', options, '' if options[:verbose]
15
+ def call(app_root:, write_rubocop_rules: false, no_fix: false, list_only: false, unsafe_fix: false, linters: nil,
16
+ target_files: nil, filenames: nil)
18
17
 
19
- Dir.chdir(options[:app_root]) do
20
- if options[:write_rubocop_rules]
18
+ Dir.chdir(app_root) do
19
+ if write_rubocop_rules
21
20
  GlLint::ExportRubocop.write_rules(app_root)
22
21
  else
23
- lint_strategy = lint_strategy_from_options(**options.slice(:no_fix, :list_only,
24
- :unsafe_fix))
25
- linter_args = options.slice(:linters, :target_files, :filenames)
26
- .merge(lint_strategy:)
27
- GlLint::Linter.new.lint(**linter_args)
22
+ lint_strategy = lint_strategy_from_options(no_fix:, list_only:, unsafe_fix:)
23
+ GlLint::Linter.new.lint(linters:, target_files:, filenames:, lint_strategy:)
28
24
  end
29
25
  end
30
26
  end
27
+
28
+ private
29
+
30
+ def lint_strategy_from_options(no_fix: false, list_only: false, unsafe_fix: false)
31
+ return :list_only if list_only
32
+ return :no_fix if no_fix
33
+
34
+ unsafe_fix ? :unsafe_fix : :fix
35
+ end
31
36
  end
32
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gl_lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Give Lively
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-08 00:00:00.000000000 Z
11
+ date: 2024-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: optparse
@@ -87,11 +87,8 @@ extensions: []
87
87
  extra_rdoc_files:
88
88
  - README.md
89
89
  files:
90
- - Gemfile
91
- - Guardfile
92
90
  - LICENSE
93
91
  - README.md
94
- - bin/lint
95
92
  - gl_lint.gemspec
96
93
  - lib/gl_lint.rb
97
94
  - lib/gl_lint/cli.rb
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- group :development, :test do
6
- gem 'guard'
7
- gem 'guard-rspec'
8
- gem 'rspec'
9
- end
10
-
11
- gemspec
data/Guardfile DELETED
@@ -1,25 +0,0 @@
1
- directories %w[lib spec]
2
-
3
- rspec_options = {
4
- cmd: 'bundle exec rspec',
5
- all_after_pass: false,
6
- all_on_start: false,
7
- failed_mode: :focus
8
- }
9
-
10
- guard :rspec, rspec_options do
11
- require 'guard/rspec/dsl'
12
- dsl = Guard::RSpec::Dsl.new(self)
13
-
14
- # Feel free to open issues for suggestions and improvements
15
-
16
- # RSpec files
17
- rspec = dsl.rspec
18
- watch(rspec.spec_helper) { rspec.spec_dir }
19
- watch(rspec.spec_support) { rspec.spec_dir }
20
- watch(rspec.spec_files)
21
-
22
- # Ruby files
23
- ruby = dsl.ruby
24
- dsl.watch_spec_files_for(ruby.lib_files)
25
- end
data/bin/lint DELETED
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'bundler/setup' # don't use rubygems, keep references internal
3
- require 'gl_lint'
4
-
5
- GlLint.run_cli(app_root: File.expand_path('..', __dir__),
6
- linters: ['rubocop'])