lintf 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 475858fee0d3177168e0dd9119c14a26e154d43da9d435970209f5d1efcb4927
4
- data.tar.gz: e16ac31059c31675c89410e716a1b441ab1ad4639bce4e359f348f5dce1a0b52
3
+ metadata.gz: 9f5fc442d091dac3a0febcd6c6c82c0cf61833fbcd77909fb2bd6e4ae0729aed
4
+ data.tar.gz: 18e1cc8e35c9e7ede67ad15a93a0ab013385a98402059ed48017fd4bc4e68eb2
5
5
  SHA512:
6
- metadata.gz: 9143f3a312a41e9dc58e98b4e0c5f1fd3f6957a2a88ffef9ce7a0f30b58df99be5a94bb2ff7fdb34ea1f080aa2e1a3d4d8d7639f0d9c95c0e0f0fa3e8acc8763
7
- data.tar.gz: a5f55c6925bbadc4e1a2d22a0880401eaa7e96e6977cd3d2a4bc5990ccb1a9c6b409562d9b918547b80510222d161e76479381646f3bc6dba9efb8a351d3605a
6
+ metadata.gz: f48709f47c47eae4bdf7b9194a097c8a4ecf5cce4d1788f07674e45385e8f511bb1412ea99fcf16ecc10396de8727eae84c16d46b66c9d32610bcb7434980af7
7
+ data.tar.gz: 646b393f03a816e392a5426d4b7567926b2518dceaf3b01366dca83a2d96a9021173105a713a5fe13177f5d925e09de39dd21ec54627fb5583928cd180799bf2
data/CHANGELOG.md CHANGED
@@ -1,11 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.0](https://rubygems.org/gems/lintf/versions/0.2.0) - 2024-12-21
4
+
5
+ - [`91816f9`](https://codeberg.org/cdfzo/lintf-rb/commit/91816f9901288c30943e038fd8bb3b9ff601ac89)
6
+ Make CLI customizable via .lintf.yml
7
+ - [`6df7d33`](https://codeberg.org/cdfzo/lintf-rb/commit/6df7d331e2f1426f6994341f8550b7d529795efe)
8
+ Use only RuboCop as runtime dependency
9
+ - [`a131a6e`](https://codeberg.org/cdfzo/lintf-rb/commit/a131a6eaf9559d2c2090a8470a687f956ee730cf)
10
+ Disable Style/ClassAndModuleChildren
11
+
3
12
  ## [0.1.0](https://rubygems.org/gems/lintf/versions/0.1.0) - 2024-12-21
4
13
 
5
- - Add Lintf CLI
6
- - Add RuboCop config
7
- - Add RuboCop Performance config
8
- - Add RuboCop Rails config
9
- - Add RuboCop RSpec config
10
- - Add RuboCop RSpecRails config
11
- - Add ERB Lint config
14
+ - [`4f26633`](https://codeberg.org/cdfzo/lintf-rb/commit/4f26633df30ce35657a33538db5ab3372544ffea)
15
+ Add Lintf CLI
16
+ - [`6276ef0`](https://codeberg.org/cdfzo/lintf-rb/commit/6276ef0bda63a2cf9dbbc9d0b3ace53a6b77bb79)
17
+ Add RuboCop config
18
+ - [`e945310`](https://codeberg.org/cdfzo/lintf-rb/commit/e94531058649d604418e529f526d1958e771b19d)
19
+ Add RuboCop Performance config
20
+ - [`ecc2872`](https://codeberg.org/cdfzo/lintf-rb/commit/ecc2872e91abcc3607753083707f944c9b46c277)
21
+ Add RuboCop Rails config
22
+ - [`50f49c8`](https://codeberg.org/cdfzo/lintf-rb/commit/50f49c878dd5313ed4bb279ab6d862e51cc7910f)
23
+ Add RuboCop RSpec config
24
+ - [`b2c16c3`](https://codeberg.org/cdfzo/lintf-rb/commit/b2c16c3368d4312b9e280968678b6dcc54af479c)
25
+ Add RuboCop RSpecRails config
26
+ - [`8353c5e`](https://codeberg.org/cdfzo/lintf-rb/commit/8353c5ef0f0db9d2a3742fcd2f071016ad55d0fe)
27
+ Add ERB Lint config
data/README.md CHANGED
@@ -1,26 +1,18 @@
1
1
  # Lintf
2
2
 
3
- Linter and formatter collection for Ruby, including configuration for RuboCop
3
+ Linter and formatter runner for Ruby, including configuration for RuboCop
4
4
  (Performance, Rails, RSpec, RSpecRails) and ERB Lint.
5
5
 
6
6
  ## Installation
7
7
 
8
- Run `bundle add lintf`.
8
+ 1. Add `gem 'lintf', require: false` to the development group in your Gemfile.
9
+ 1. Run `bundle`.
9
10
 
10
11
  ## Configuration
11
12
 
12
13
  ### RuboCop
13
14
 
14
- Edit `.rubocop.yml`:
15
-
16
- ```yml
17
- inherit_gem:
18
- lintf: config/base.yml
19
- ```
20
-
21
- This will include all configured cops.
22
-
23
- Alternatively, you can select the cops you want:
15
+ Edit `.rubocop.yml` and select the cops you want to use:
24
16
 
25
17
  ```yml
26
18
  inherit_gem:
@@ -32,9 +24,12 @@ inherit_gem:
32
24
  - config/rubocop-rspec_rails.yml
33
25
  ```
34
26
 
27
+ Don't forget to add the cop's gem to your Gemfile as well, since Lintf only
28
+ includes the `rubocop` gem.
29
+
35
30
  ### ERB Lint
36
31
 
37
- Edit `.erb_lint.yml`:
32
+ Edit `.erb_lint.yml` and add `erb_lint` to your Gemfile:
38
33
 
39
34
  ```yml
40
35
  inherit_gem:
@@ -43,31 +38,51 @@ inherit_gem:
43
38
 
44
39
  ## Usage
45
40
 
46
- By default, the CLI checks all touched files in the current branch using
47
- `git diff origin/main`. You can change this behavior by passing the following
48
- options:
41
+ ### Config File
49
42
 
50
- - `-a`: All files tracked by Git (uses `git ls-files`)
51
- - `-f`: Automatically fix problems (dangerous, e.g. `rubocop -A`)
43
+ You can create your own tool definitions in a `.lintf.yml` file and add them to
44
+ the `run` key, or override the default. Your config will be deep merged with the
45
+ [default configuration](https://codeberg.org/cdfzo/lintf-rb/src/branch/main/config/lintf.yml).
52
46
 
53
- ### Available Linters
47
+ ### CLI
54
48
 
55
- The following linters will be executed (in this order) if no arguments are given
56
- and the linter's configuration file is present:
49
+ By default, Lintf checks all touched files in the current branch using
50
+ `git diff origin/main`. You can change this behavior by passing the following
51
+ options to the CLI:
57
52
 
58
- - `r`/`rubocop`: RuboCop
59
- - `er`/`erblint`: ERB Lint
53
+ - `-a`: All files tracked by Git (uses `git ls-files`)
54
+ - `-f`: Fix problems automatically (i.e. autocorrect)
55
+
56
+ Other flags are passed to the tools (e.g. `lintf rubocop --help`).
60
57
 
61
58
  ### Examples
62
59
 
63
60
  Here are some examples of how to use the CLI:
64
61
 
65
- - `bundle exec lintf`: Run all linters, but only on touched files
66
- - `bundle exec lintf -f`: **Fix/format** touched files with all linters
62
+ - `bundle exec lintf`: Run all tools, but only on touched files
63
+ - `bundle exec lintf -f`: **Fix/format** touched files with all tools
67
64
  - `bundle exec lintf er r`: Run **ERB Lint**, then **RuboCop**
68
65
  - `bundle exec lintf -a rubocop`: Check **all** files with RuboCop
69
66
  - `bundle exec lintf -fa r`: **Format all** files with RuboCop
70
67
 
68
+ Here are some examples of how to override the default config with `.lintf.yml`:
69
+
70
+ ```yml
71
+ run: [rubocop, my_custom_linter]
72
+
73
+ rubocop:
74
+ fix: -a
75
+
76
+ my_custom_linter:
77
+ alias: mcl
78
+ run: bundle exec my_custom_linter --fail-fast
79
+ files: [md, yml]
80
+ ```
81
+
82
+ This changes the RuboCop autocorrection from the default `-A` to the safe `-a`
83
+ and defines a new tool that will be run by default (after rubocop) or via
84
+ `bundle exec lintf my_custom_linter` or `bundle exec lintf mcl`
85
+
71
86
  ## License
72
87
 
73
88
  Lintf is released under the terms of the
data/bin/lintf CHANGED
@@ -1,63 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- CONFIG = {
5
- RuboCop: {
6
- config: '.rubocop.yml',
7
- run: 'bundle exec rubocop -c .rubocop.yml --force-exclusion db/schema.rb',
8
- fix: '-A',
9
- files: %w[rb rake gemspec],
10
- },
11
- 'ERB Lint': {
12
- config: '.erb_lint.yml',
13
- run: 'bundle exec erb_lint',
14
- fix: '-a',
15
- files: %w[erb],
16
- },
17
- }.freeze
4
+ lib_path = File.expand_path '../lib', __dir__
5
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include? lib_path
18
6
 
19
- options = {}
20
- runners = []
7
+ require 'lintf/cli'
21
8
 
22
- # Get runners and options
23
- ARGV.each do |argument|
24
- if argument.start_with? '-'
25
- argument[1..].chars.each do |option|
26
- case option
27
- when 'a' then options[:all] = true
28
- when 'f' then options[:fix] = true
29
- else
30
- puts "error: unknown option '#{argument}'"
31
- exit 1
32
- end
33
- end
34
- else
35
- case argument
36
- when 'er', 'erblint' then runners << :'ERB Lint'
37
- when 'r', 'rubocop' then runners << :RuboCop
38
- else
39
- puts "error: unknown linter '#{argument}'"
40
- exit 1
41
- end
42
- end
43
- end
44
-
45
- TRACKED_FILES = if options[:all] || `git branch --show-current`.strip == 'main'
46
- `git ls-files`
47
- else
48
- `git diff origin/main --diff-filter=dxb --name-only`
49
- end.split "\n"
50
-
51
- # Execute runners
52
- (runners.any? ? runners.uniq : CONFIG.keys).each do |name|
53
- runner = CONFIG[name]
54
- next unless File.file? runner[:config]
55
-
56
- file_extensions = runner[:files].map { |extension| ".#{extension}" }
57
- files = TRACKED_FILES.filter { |f| f.end_with?(*file_extensions) }.join ' '
58
- next if files.empty?
59
-
60
- puts "---- Executing #{name} ----"
61
- option = runner[options[:fix] ? :fix : :check]
62
- exit 1 unless system "#{runner[:run]} #{option} #{files}"
63
- end
9
+ Lintf::CLI.new.run
data/config/lintf.yml ADDED
@@ -0,0 +1,29 @@
1
+ # List of tools to run in this exact order if no arguments are provided in the
2
+ # CLI. Can be either the key/name or alias of the defined tool (see `# Tools`).
3
+ run: [rubocop, erblint]
4
+
5
+ # Use -a/-f in the CLI to enable them or change it here permanently.
6
+ all: false
7
+ fix: false
8
+
9
+ # Tools
10
+ rubocop:
11
+ # Alias to run the tool in the CLI (e.g. `bundle exec lintf r`). The key can
12
+ # be used as well (e.g. `bundle exec lintf rubocop`).
13
+ alias: r
14
+ # Only run the tool if this file exists. Remove this key to always run it.
15
+ config: .rubocop.yml
16
+ # Command to run the tool. The files are appended to this command.
17
+ run: bundle exec rubocop -c .rubocop.yml --force-exclusion db/schema.rb
18
+ # Flag to enable autocorrection. Appended to `run` when `-f` is enabled.
19
+ fix: -A
20
+ # File extensions to include. Remove this key to use all files (i.e. `.`, so
21
+ # even files not tracked by Git).
22
+ files: [rb, rake, gemspec]
23
+
24
+ erblint:
25
+ alias: er
26
+ config: .erb_lint.yml
27
+ run: bundle exec erb_lint
28
+ fix: -a
29
+ files: [erb]
data/config/rubocop.yml CHANGED
@@ -1027,10 +1027,7 @@ Style/CharacterLiteral:
1027
1027
  Enabled: true
1028
1028
 
1029
1029
  Style/ClassAndModuleChildren:
1030
- Enabled: true
1031
- EnforcedStyle: compact
1032
- Exclude:
1033
- - '**/config/application.rb'
1030
+ Enabled: false
1034
1031
 
1035
1032
  Style/ClassCheck:
1036
1033
  Enabled: true
data/lib/lintf/cli.rb ADDED
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'psych'
4
+
5
+ module Lintf
6
+ class CLI
7
+ def run
8
+ parse_args
9
+ tools_to_execute.each do |tool|
10
+ next if tool[:config] && !File.file?(tool[:config])
11
+
12
+ execute tool
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def merge_config(config)
19
+ custom_config = Psych.safe_load_file '.lintf.yml', symbolize_names: true
20
+
21
+ custom_config.each do |key, value|
22
+ if config[key].is_a? Hash
23
+ config[key].merge! value
24
+ else
25
+ config[key] = value
26
+ end
27
+ end
28
+ end
29
+
30
+ def config
31
+ @config ||= begin
32
+ config_file = File.expand_path '../../config/lintf.yml', __dir__
33
+ config = Psych.safe_load_file config_file, symbolize_names: true
34
+
35
+ merge_config config if File.file? '.lintf.yml'
36
+ config
37
+ rescue StandardError => e
38
+ error "invalid lintf config file: #{e.message}"
39
+ end
40
+ end
41
+
42
+ def parse_args
43
+ config[:flags] = []
44
+
45
+ ARGV.each do |arg|
46
+ if arg.start_with? '--'
47
+ config[:flags] << arg
48
+ elsif arg.start_with? '-'
49
+ arg[1..].chars.each { |name| find_and_set_flag name }
50
+ else
51
+ (config[:tools] ||= []) << find_tool(arg)
52
+ end
53
+ end
54
+ end
55
+
56
+ def flags
57
+ @flags ||= { a: :all, f: :fix }
58
+ end
59
+
60
+ def find_and_set_flag(name)
61
+ flag = flags[name.to_sym]
62
+
63
+ if flag
64
+ config[flag] = true
65
+ else
66
+ (config[:flags] ||= []) << "-#{name}"
67
+ end
68
+ end
69
+
70
+ def tools
71
+ @tools ||= config.values.filter { |v| v.is_a? Hash }
72
+ end
73
+
74
+ def find_tool(name)
75
+ config[name.to_sym] || tools.find { |tool| tool[:alias] == name } ||
76
+ error("unknown tool '#{name}'")
77
+ end
78
+
79
+ def files
80
+ @files ||= if config[:all] || `git branch --show-current`.strip == 'main'
81
+ `git ls-files`
82
+ else
83
+ `git diff origin/main --diff-filter=dxb --name-only`
84
+ end.split "\n"
85
+ end
86
+
87
+ def files_for(tool)
88
+ return '.' unless tool[:files]
89
+
90
+ file_extensions = tool[:files].map { |extension| ".#{extension}" }
91
+ files.filter { |file| file.end_with?(*file_extensions) }.join ' '
92
+ end
93
+
94
+ def fix_or_check
95
+ @fix_or_check ||= config[:fix] ? :fix : :check
96
+ end
97
+
98
+ def tools_to_execute
99
+ config[:tools] || config[:run].map { |name| find_tool name }
100
+ end
101
+
102
+ def execute(tool)
103
+ command = "#{tool[:run]} #{tool[fix_or_check]} #{config[:flags].join ' '}"
104
+ files = files_for tool
105
+
106
+ puts "\x1b[2m$ #{command}\x1b[0m"
107
+
108
+ if files.empty?
109
+ return puts "(no files #{config[:all] ? 'found' : 'touched'})"
110
+ end
111
+
112
+ exit 1 unless system "#{command} #{files}"
113
+ end
114
+
115
+ def error(message)
116
+ puts "error: #{message}"
117
+ exit 1
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lintf
4
+ VERSION = '0.2.0'
5
+ end
data/lib/lintf.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Lintf
4
- VERSION = '0.1.0'
5
- end
3
+ require 'lintf/cli'
4
+ require 'lintf/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lintf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cdfzo
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2024-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: erb_lint
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 0.7.0
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 0.7.0
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rubocop
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -38,64 +24,8 @@ dependencies:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
26
  version: '1.69'
41
- - !ruby/object:Gem::Dependency
42
- name: rubocop-performance
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.23'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.23'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop-rails
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.27'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.27'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop-rspec
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.3'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.3'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-rspec_rails
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '2.30'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '2.30'
97
- description: Linter and formatter collection for Ruby, including configuration for
98
- RuboCop (Performance, Rails, RSpec, RSpecRails) and ERB Lint.
27
+ description: Linter and formatter runner for Ruby, including configuration for RuboCop
28
+ (Performance, Rails, RSpec, RSpecRails) and ERB Lint.
99
29
  email: cdfzo@pm.me
100
30
  executables:
101
31
  - lintf
@@ -108,12 +38,15 @@ files:
108
38
  - bin/lintf
109
39
  - config/base.yml
110
40
  - config/erb_lint.yml
41
+ - config/lintf.yml
111
42
  - config/rubocop-performance.yml
112
43
  - config/rubocop-rails.yml
113
44
  - config/rubocop-rspec.yml
114
45
  - config/rubocop-rspec_rails.yml
115
46
  - config/rubocop.yml
116
47
  - lib/lintf.rb
48
+ - lib/lintf/cli.rb
49
+ - lib/lintf/version.rb
117
50
  homepage: https://codeberg.org/cdfzo/lintf-rb
118
51
  licenses:
119
52
  - MIT
@@ -142,5 +75,5 @@ requirements: []
142
75
  rubygems_version: 3.5.22
143
76
  signing_key:
144
77
  specification_version: 4
145
- summary: Linter and formatter collection for Ruby.
78
+ summary: Linter and formatter runner for Ruby.
146
79
  test_files: []