Permalink
Browse files

Updated README to reflect CLI usage. Fixed splat bug, failing test, a…

…nd --only flag.
  • Loading branch information...
1 parent e8df989 commit a02641ba6b4430646c6761a6225aa2e157393c32 Michael Edgar committed Aug 12, 2011
View
@@ -63,15 +63,74 @@ Installing
To install LASER, use the following command:
- $ gem install laser
+ $ gem install laser --prerelease
-(Add `sudo` if you're installing under a POSIX system as root)
+(Add `sudo` if you're installing to a directory requiring root privileges to write)
Usage
-----
There are a couple of ways to use LASER. It has a command-line implementation,
-and a Rake task. They will be documented further in the future.
+and a Rake task.
+
+The command-line implementation is still having its flags worked out for usability -
+right now, there's some flexibility, but they're a huge pain to use. Also, the style-related
+analyses are handled slightly differently from semantic analyses. So bear with me.
+
+When analyzing for semantic issues, `require`s and `load`s are *always* followed. This
+may become a command-line flag in the future, but it isn't now.
+
+When analyzing for style issues, the file in question must be listed on the command line.
+
+Example runs:
+
+```
+$ cat temp.rb
+class Foo
+ def initialize(x, *args)
+ a, b = args[1..2]
+ end
+end
+Foo.new(gets, gets)
+
+$ laser temp.rb
+4 warnings found. 0 are fixable.
+================================
+(stdin):3 Error (4) - Variable defined but not used: x
+(stdin):3 Error (6) - LHS never assigned - defaults to nil
+(stdin):3 Error (4) - Variable defined but not used: a
+(stdin):3 Error (4) - Variable defined but not used: b
+```
+
+Cool! If you want to specify a set of warnings to consider, you can use the `--only` flag. And
+if you want style errors to be fixed, use `--fix`. For example:
+
+```
+$ cat tempstyle.rb
+x = 0
+x+=10 # extra space at the end of this line
+# blank lines following
+
+
+$ laser --only OperatorSpacing,ExtraBlankLinesWarning,InlineCommentSpaceWarning,ExtraWhitespaceWarning --fix tempstyle.rb
+
+$ cat tempstyle.rb
+x = 0
+x += 10 # extra space at the end of this line
+# blank lines following$ (prompt)
+```
+
+What happened there is:
+
+1. Inline comments were set to 2 spaces away from their line of code. This will be configurable in the future.
+2. The `+=` operator was properly spaced.
+3. The extra spaces at the end of line 2 were removed
+4. The blank lines at the end of the file were removed.
+
+Cool! Of course, all those would have happened if you just ran `laser --fix tempstyle.rb`, but I wanted to demonstrate
+how to specify individual warnings. Again, that's going to have to be made a lot easier - I've experimented with giving
+each warning a "short name" that gets emitted alongside the warning, but that has some discoverability issues. We'll see
+where that goes.
Changelog
---------
View
@@ -1,6 +1,25 @@
require 'rubygems'
require 'rake'
+# switch to false if the gem can't load
+if true
+ begin
+ require 'laser'
+ Laser::Rake::LaserTask.new(:laser) do |laser|
+ laser.libs << 'lib' << 'spec'
+ laser.using << :all << Laser::LineLengthMaximum(100) << Laser::LineLengthWarning(80)
+ laser.options = '--debug --fix'
+ laser.fix << Laser::ExtraBlankLinesWarning << Laser::ExtraWhitespaceWarning << Laser::LineLengthWarning(80)
+ end
+ rescue LoadError,Exception => err
+ $:.unshift(File.dirname(__FILE__))
+ require 'lib/laser/version'
+ task :laser do
+ abort 'Laser is not available. In order to run laser, you must: sudo gem install laser'
+ end
+ end
+end
+
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
@@ -11,7 +30,7 @@ begin
gem.homepage = 'http://github.com/michaeledgar/laser'
gem.authors = ['Michael Edgar']
gem.extensions = ['ext/laser/extconf.rb']
-
+ gem.version = Laser::Version::STRING
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
@@ -40,23 +59,6 @@ Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end
-# switch to false if the gem can't load
-if false
- begin
- require 'laser'
- Laser::Rake::LaserTask.new(:laser) do |laser|
- laser.libs << 'lib' << 'spec'
- laser.using << :all << Laser::LineLengthMaximum(100) << Laser::LineLengthWarning(80)
- laser.options = '--debug --fix'
- laser.fix << Laser::ExtraBlankLinesWarning << Laser::ExtraWhitespaceWarning << Laser::LineLengthWarning(80)
- end
- rescue LoadError => err
- task :laser do
- abort 'Laser is not available. In order to run laser, you must: sudo gem install laser'
- end
- end
-end
-
task rebuild: [:gemspec, :build, :install] do
%x(rake laser)
end
View
@@ -1,5 +1,7 @@
#!/usr/bin/env ruby
+require 'rubygems'
+require 'bundler/setup'
+Bundler.require(:default)
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'laser'
-
-Laser::Runner.new(ARGV).run
+Laser::Runner.new(ARGV.dup).run
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{laser}
- s.version = "0.6.0"
+ s.version = "0.7.0.pre1"
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Michael Edgar}]
- s.date = %q{2011-07-26}
+ s.date = %q{2011-08-12}
s.description = %q{Laser is an advanced static analysis tool for Ruby.}
s.email = %q{michael.j.edgar@dartmouth.edu}
s.executables = [%q{laser}]
@@ -55,7 +55,14 @@ Gem::Specification.new do |s|
"lib/laser/analysis/argument_expansion.rb",
"lib/laser/analysis/arity.rb",
"lib/laser/analysis/bindings.rb",
- "lib/laser/analysis/bootstrap.rb",
+ "lib/laser/analysis/bootstrap/bootstrap.rb",
+ "lib/laser/analysis/bootstrap/laser_class.rb",
+ "lib/laser/analysis/bootstrap/laser_method.rb",
+ "lib/laser/analysis/bootstrap/laser_module.rb",
+ "lib/laser/analysis/bootstrap/laser_module_copy.rb",
+ "lib/laser/analysis/bootstrap/laser_object.rb",
+ "lib/laser/analysis/bootstrap/laser_proc.rb",
+ "lib/laser/analysis/bootstrap/laser_singleton_class.rb",
"lib/laser/analysis/comments.rb",
"lib/laser/analysis/control_flow.rb",
"lib/laser/analysis/control_flow/alias_analysis.rb",
@@ -73,7 +80,6 @@ Gem::Specification.new do |s|
"lib/laser/analysis/control_flow/unused_variables.rb",
"lib/laser/analysis/control_flow/yield_properties.rb",
"lib/laser/analysis/errors.rb",
- "lib/laser/analysis/laser_class.rb",
"lib/laser/analysis/laser_utils.rb",
"lib/laser/analysis/lexical_analysis.rb",
"lib/laser/analysis/method_call.rb",
@@ -86,6 +92,7 @@ Gem::Specification.new do |s|
"lib/laser/analysis/sexp_extensions/type_inference.rb",
"lib/laser/analysis/signature.rb",
"lib/laser/analysis/special_methods/send.rb",
+ "lib/laser/analysis/unused_methods.rb",
"lib/laser/analysis/visitor.rb",
"lib/laser/annotation_parser/annotations.treetop",
"lib/laser/annotation_parser/annotations_parser.rb",
@@ -119,7 +126,6 @@ Gem::Specification.new do |s|
"lib/laser/standard_library/comparable.rb",
"lib/laser/standard_library/complex.rb",
"lib/laser/standard_library/enumerable.rb",
- "lib/laser/standard_library/errno.rb",
"lib/laser/standard_library/exceptions.rb",
"lib/laser/standard_library/fixnum.rb",
"lib/laser/standard_library/float.rb",
@@ -171,6 +177,7 @@ Gem::Specification.new do |s|
"lib/laser/warnings/rescue_exception.rb",
"lib/laser/warnings/semicolon.rb",
"lib/laser/warnings/sexp_errors.rb",
+ "lib/laser/warnings/uncalled_method_warning.rb",
"lib/laser/warnings/useless_double_quotes.rb",
"spec/analysis_specs/annotations_spec.rb",
"spec/analysis_specs/annotations_specs/comment_attachment_spec.rb",
@@ -188,6 +195,7 @@ Gem::Specification.new do |s|
"spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb",
"spec/analysis_specs/control_flow_specs/simulation_spec.rb",
"spec/analysis_specs/control_flow_specs/spec_helper.rb",
+ "spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb",
"spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb",
"spec/analysis_specs/control_flow_specs/unused_variable_spec.rb",
"spec/analysis_specs/control_flow_specs/yield_properties_spec.rb",
@@ -204,6 +212,7 @@ Gem::Specification.new do |s|
"spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb",
"spec/analysis_specs/sexp_spec.rb",
"spec/analysis_specs/spec_helper.rb",
+ "spec/analysis_specs/unused_methods_spec.rb",
"spec/analysis_specs/visitor_spec.rb",
"spec/annotation_parser_specs/annotations_parser_spec.rb",
"spec/annotation_parser_specs/class_annotation_parser_spec.rb",
View
@@ -93,5 +93,6 @@ def self.debug?
require 'laser/warning'
require 'laser/scanner'
+require 'laser/version'
# All methods created from the stdlib should never be marked as unused.
Laser::Analysis::Bootstrap.load_standard_library
@@ -1576,7 +1576,7 @@ def multiple_assign_instruct(lhs, rhs, opts={})
if fixed_size >= lhs_size
wasted_rhs_splat(rhs)
else
- declare_instruct(:expect_tuple_size, :<, lhs_size - fixed_size + 1, varying)
+ declare_instruct(:expect_tuple_size, :==, lhs_size - fixed_size, varying)
end
fixed[0...lhs_size].each_with_index do |val, idx|
single_assign_instruct(lhs[idx], val)
View
@@ -45,7 +45,7 @@ def handle_global_options(settings)
end
if (only_name = settings[:only])
@fix = @using = Warning.concrete_warnings.select do |w|
- (w.name && w.name.index(only_name)) || (w.short_name && only_name.index(w.short_name))
+ (w.name && only_name.index(w.name)) || (w.short_name && w.short_name.index(only_name))
end
end
if settings[:profile]
View
@@ -0,0 +1,14 @@
+module Laser
+ module Version
+ MAJOR = 0
+ MINOR = 7
+ PATCH = 0
+ BUILD = 'pre1'
+
+ if BUILD.empty?
+ STRING = [MAJOR, MINOR, PATCH].compact.join('.')
+ else
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
+ end
+ end
+end
@@ -4,7 +4,7 @@ class Laser::InlineCommentSpaceWarning < Laser::LineWarning
DEFAULT_SPACE = 2
type :style
short_desc 'Inline comment spacing error'
- desc { "Inline comments must be at least #{@settings[OPTION_KEY]} spaces from code." }
+ desc { "Inline comments must be exactly #{@settings[OPTION_KEY]} spaces from code." }
opt OPTION_KEY, 'Number of spaces between code and inline comments', default: DEFAULT_SPACE
fixable true
@@ -58,7 +58,7 @@ def baz
EOF
@methods = UnusedMethodDetection.unused_methods
- Set[@methods].should ==
+ Set.new(@methods).should ==
Set[ClassRegistry['UnusedMethod2'].instance_method(:foo),
ClassRegistry['UnusedMethod3'].instance_method(:baz)]
end

0 comments on commit a02641b

Please sign in to comment.