lintf 0.1.0 → 0.3.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: 26b79fcf340bc25f76e1604f62993f933d46c7b54ba27479b0ca7fa20e8fa258
4
+ data.tar.gz: c27ef1799a2a37df14ec4814f862710005219e69517d2083531e66b1573ecd38
5
5
  SHA512:
6
- metadata.gz: 9143f3a312a41e9dc58e98b4e0c5f1fd3f6957a2a88ffef9ce7a0f30b58df99be5a94bb2ff7fdb34ea1f080aa2e1a3d4d8d7639f0d9c95c0e0f0fa3e8acc8763
7
- data.tar.gz: a5f55c6925bbadc4e1a2d22a0880401eaa7e96e6977cd3d2a4bc5990ccb1a9c6b409562d9b918547b80510222d161e76479381646f3bc6dba9efb8a351d3605a
6
+ metadata.gz: 9afccfad4f51f5883d8212f9215485fd5bef94f2f35e282fbf9ab5918943058bf9fb10eb264fb6eb3a6c924e73f29810aae2fdd1787e13dbfee3df81c4b7869a
7
+ data.tar.gz: 950624925fb1d421869dd54de06445b7991d26b70792e09c93af5b25a1fdc6c8aa89b0a51eb57e83caad729da86a92f34d648385299d8d74eb1dc729ad80c3aa
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]
@@ -308,9 +308,6 @@ RSpec/SpecFilePathFormat:
308
308
  RSpec/SpecFilePathSuffix:
309
309
  Enabled: true
310
310
 
311
- RSpec/StringAsInstanceDoubleConstant:
312
- Enabled: true
313
-
314
311
  RSpec/StubbedMock:
315
312
  Enabled: true
316
313
 
data/config/rubocop.yml CHANGED
@@ -785,7 +785,6 @@ Lint/UnreachableLoop:
785
785
 
786
786
  Lint/UnusedBlockArgument:
787
787
  Enabled: true
788
- IgnoreEmptyBlocks: false
789
788
 
790
789
  Lint/UnusedMethodArgument:
791
790
  Enabled: true
@@ -1027,10 +1026,7 @@ Style/CharacterLiteral:
1027
1026
  Enabled: true
1028
1027
 
1029
1028
  Style/ClassAndModuleChildren:
1030
- Enabled: true
1031
- EnforcedStyle: compact
1032
- Exclude:
1033
- - '**/config/application.rb'
1029
+ Enabled: false
1034
1030
 
1035
1031
  Style/ClassCheck:
1036
1032
  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.3.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,130 +1,58 @@
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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cdfzo
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-12-21 00:00:00.000000000 Z
10
+ date: 2025-01-24 00:00:00.000000000 Z
12
11
  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
12
  - !ruby/object:Gem::Dependency
28
13
  name: rubocop
29
14
  requirement: !ruby/object:Gem::Requirement
30
15
  requirements:
31
16
  - - "~>"
32
17
  - !ruby/object:Gem::Version
33
- version: '1.69'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- 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'
18
+ version: '1.70'
90
19
  type: :runtime
91
20
  prerelease: false
92
21
  version_requirements: !ruby/object:Gem::Requirement
93
22
  requirements:
94
23
  - - "~>"
95
24
  - !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.
25
+ version: '1.70'
26
+ description: Linter and formatter runner for Ruby, including configuration for RuboCop
27
+ (Performance, Rails, RSpec, RSpecRails) and ERB Lint.
99
28
  email: cdfzo@pm.me
100
29
  executables:
101
30
  - lintf
102
31
  extensions: []
103
32
  extra_rdoc_files: []
104
33
  files:
105
- - CHANGELOG.md
106
34
  - LICENSE
107
35
  - README.md
108
36
  - bin/lintf
109
- - config/base.yml
110
37
  - config/erb_lint.yml
38
+ - config/lintf.yml
111
39
  - config/rubocop-performance.yml
112
40
  - config/rubocop-rails.yml
113
41
  - config/rubocop-rspec.yml
114
42
  - config/rubocop-rspec_rails.yml
115
43
  - config/rubocop.yml
116
44
  - lib/lintf.rb
45
+ - lib/lintf/cli.rb
46
+ - lib/lintf/version.rb
117
47
  homepage: https://codeberg.org/cdfzo/lintf-rb
118
48
  licenses:
119
49
  - MIT
120
50
  metadata:
121
- homepage_uri: https://codeberg.org/cdfzo/lintf-rb
122
51
  source_code_uri: https://codeberg.org/cdfzo/lintf-rb
123
52
  bug_tracker_uri: https://codeberg.org/cdfzo/lintf-rb/issues
124
53
  changelog_uri: https://codeberg.org/cdfzo/lintf-rb/src/branch/main/CHANGELOG.md
125
54
  documentation_uri: https://codeberg.org/cdfzo/lintf-rb/src/branch/main/README.md
126
55
  rubygems_mfa_required: 'true'
127
- post_install_message:
128
56
  rdoc_options: []
129
57
  require_paths:
130
58
  - lib
@@ -139,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
67
  - !ruby/object:Gem::Version
140
68
  version: '0'
141
69
  requirements: []
142
- rubygems_version: 3.5.22
143
- signing_key:
70
+ rubygems_version: 3.6.3
144
71
  specification_version: 4
145
- summary: Linter and formatter collection for Ruby.
72
+ summary: Linter and formatter runner for Ruby.
146
73
  test_files: []
data/CHANGELOG.md DELETED
@@ -1,11 +0,0 @@
1
- # Changelog
2
-
3
- ## [0.1.0](https://rubygems.org/gems/lintf/versions/0.1.0) - 2024-12-21
4
-
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
data/config/base.yml DELETED
@@ -1,6 +0,0 @@
1
- inherit_from:
2
- - rubocop.yml
3
- - rubocop-performance.yml
4
- - rubocop-rails.yml
5
- - rubocop-rspec.yml
6
- - rubocop-rspec_rails.yml