-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new Lint/ScriptPermission cop #4342
Conversation
0de9b32
to
310b339
Compare
config/enabled.yml
Outdated
@@ -868,6 +868,13 @@ Style/SafeNavigation: | |||
safe navigation (`&.`). | |||
Enabled: true | |||
|
|||
Style/ScriptPermission: | |||
Description: 'Set file permission with `chmod +x`.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use some more generic wording here - after all some people use Windows. ;-)
module RuboCop | ||
module Cop | ||
module Style | ||
# This cop checks whether the file permission is executable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be extended a bit - after all the cop applies just scripts. Frankly, from this description people looking the manual would be quite confused.
This cop should certain check that the script files actually have shebang in them. Right now this is going to ignore every scripts that's not in Guess some logic can be used from other cops that we have which are dealing with shebangs. |
310b339
to
270ac02
Compare
@bbatsov Thanks for your code-review! I have addressed your feedbacks. Please review this codes, if you have a chance :) |
# This cop checks if a file which has a shebang line as | ||
# its first line is granted execute permission. | ||
class ScriptPermission < Cop | ||
MSG = 'Grant script file execute permission.'.freeze |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should mention the file name here, as this wording might convince some people. I'd also use working like Script file X doesn't have execute permission.
(or something similar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. I'll fix it. Thanks!!
Please, update the specs to use the new rspec helpers recently added by @backus. |
This should probably go under the |
270ac02
to
46c05a1
Compare
I'm having a problem with this cop, it says my I have tried
Notice that all files have the same permissions, but only this one is erroring out.
I have checked and the first line is #!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
puts "\n== Updating database =="
system! 'bin/rails db:migrate'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end I have also tried deleting and recreating the file and rewriting the shebang line. Also, whatever happened to #3659? I agree that this is out of scope. |
@zavan I think the buffer/cache might be causing the problem. In my case, the cop complained correctly that a script file wasn't executable and it didn't shut up until I changed content of the file (add/delete an empty line) |
This cop checks if a file which has a shebang line as
its first line is granted execute permission.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
rake generate_cops_documentation
(required only when you've added a new cop or changed the configuration/documentation of an existing cop).