1414# KIND, either express or implied. See the License for the
1515# specific language governing permissions and limitations
1616# under the License.
17-
1817namespace "lint" do
1918 module RuboCLI
2019 def self . run! ( *args )
@@ -25,28 +24,44 @@ namespace "lint" do
2524 end
2625 end
2726
28- # task that runs lint report
29- desc "Report all Lint Cops"
30- task "report" do
31- RuboCLI . run! ( "--lint" )
27+ desc "Report all Lint Cops. Optional: Specify one or more files"
28+ task :report , [ :file ] do |t , args |
29+ files = [ args [ :file ] , *args . extras ] . compact
30+
31+ if files . empty?
32+ RuboCLI . run! ( "--lint" )
33+ else
34+ puts "Running lint report on specific files: #{ files . join ( ', ' ) } "
35+ RuboCLI . run! ( "--lint" , *files )
36+ end
3237 end
3338
34- # Tasks automatically fixes a Cop passed as a parameter (e.g. Lint/DeprecatedClassMethods)
35- # TODO: Add a way to autocorrect all cops, and not just the one passed as parameter
36- desc "Automatically fix all instances of a Cop passed as a parameter"
37- task "correct" , [ :cop ] do |t , args |
39+ # Tasks automatically fixes a Cop passed as a parameter
40+ desc "Automatically fix all instances of a Cop passed as a parameter. Optional: Specify one or more files"
41+ task :correct , [ :cop ] do |t , args |
3842 if args [ :cop ] . to_s . empty?
3943 puts "No Cop has been provided, aborting..."
4044 exit ( 0 )
4145 else
42- puts "Attempting to correct Lint issues for: #{ args [ :cop ] . to_s } "
43- RuboCLI . run! ( "--autocorrect-all" , "--only" , args [ :cop ] . to_s )
46+ files = args . extras
47+ if files . empty?
48+ puts "Attempting to correct Lint issues for: #{ args [ :cop ] } "
49+ RuboCLI . run! ( "--autocorrect-all" , "--only" , args [ :cop ] )
50+ else
51+ puts "Attempting to correct Lint issues for #{ args [ :cop ] } in files: #{ files . join ( ', ' ) } "
52+ RuboCLI . run! ( "--autocorrect-all" , "--only" , args [ :cop ] , *files )
53+ end
4454 end
4555 end
4656
47- # task that automatically fixes code formatting
48- desc "Automatically fix Layout Cops"
49- task "format" do
50- RuboCLI . run! ( "--fix-layout" )
57+ desc "Automatically fix Layout Cops. Optional: Specify one or more files"
58+ task :format , [ :file ] do |t , args |
59+ files = [ args [ :file ] , *args . extras ] . compact
60+ if files . empty?
61+ RuboCLI . run! ( "--fix-layout" )
62+ else
63+ puts "Running format fixes on specific files: #{ files . join ( ', ' ) } "
64+ RuboCLI . run! ( "--fix-layout" , *files )
65+ end
5166 end
52- end
67+ end
0 commit comments