How do I use nitpick

M

Michael W. Ryder

I was looking for a program like lint in C and came across nitpick. I
installed the gem but am not sure where to go from there. With lint one
ran it from the command prompt with the file name. I don't know how
to do this with gems. If I try to run it like lint I get over a dozen
lines of error messages and no output.
 
H

Hassan Schroeder

I was looking for a program like lint in C and came across nitpick. =A0I
installed the gem but am not sure where to go from there. =A0With lint on= e
=A0ran it from the command prompt with the file name. =A0I don't know how= to do
this with gems. =A0If I try to run it like lint I get over a dozen lines = of
error messages and no output.

ripple:~/$ sudo gem install nitpick
Password:
Successfully installed trollop-1.14
Successfully installed nitpick-1.0.2
2 gems installed
Installing ri documentation for trollop-1.14...
Installing ri documentation for nitpick-1.0.2...
Installing RDoc documentation for trollop-1.14...
Installing RDoc documentation for nitpick-1.0.2...
ripple:~/$ which nitpick
/usr/bin/nitpick
ripple:~/$ nitpick --help
Nitpick is a lint-like static code analyzer for Ruby.

Usage: `nitpick [(--only str | --except str)*|-h] file1.rb file2.rb`

By default, nitpick will analyze *all* loaded code. To reduce the noise:
--only, -o <s>: Nitpick only classes/modules that match this string.
--except, -e <s>: Don't nitpick classes/modules that match this string.
--help, -h: Show this message
ripple:~/$

Are you sure your installation ran all the way through?

--=20
Hassan Schroeder ------------------------ (e-mail address removed)
twitter: @hassan
 
M

Michael W. Ryder

Hassan said:
I was looking for a program like lint in C and came across nitpick. I
installed the gem but am not sure where to go from there. With lint one
ran it from the command prompt with the file name. I don't know how to do
this with gems. If I try to run it like lint I get over a dozen lines of
error messages and no output.

ripple:~/$ sudo gem install nitpick
Password:
Successfully installed trollop-1.14
Successfully installed nitpick-1.0.2
2 gems installed
Installing ri documentation for trollop-1.14...
Installing ri documentation for nitpick-1.0.2...
Installing RDoc documentation for trollop-1.14...
Installing RDoc documentation for nitpick-1.0.2...
ripple:~/$ which nitpick
/usr/bin/nitpick
ripple:~/$ nitpick --help
Nitpick is a lint-like static code analyzer for Ruby.

Usage: `nitpick [(--only str | --except str)*|-h] file1.rb file2.rb`

By default, nitpick will analyze *all* loaded code. To reduce the noise:
--only, -o <s>: Nitpick only classes/modules that match this string.
--except, -e <s>: Don't nitpick classes/modules that match this string.
--help, -h: Show this message
ripple:~/$

Are you sure your installation ran all the way through?

The first time it installed a bunch of dependencies. I just ran it
again and after saying that it was installing RDoc files for nitpick the
following message appeared:
lib/nitpick/sexp_extension.rb:3:23: ':' not followed by identified or
operator
Trying to just use nitpick --help results in a bunch of error messages.
Could this be related to the version of Ruby (1.8.4) or that I am
running this on Windows XP Pro?
 
R

Ryan Davis

The first time it installed a bunch of dependencies. I just ran it
again and after saying that it was installing RDoc files for nitpick
the following message appeared:
lib/nitpick/sexp_extension.rb:3:23: ':' not followed by identified
or operator
Trying to just use nitpick --help results in a bunch of error
messages. Could this be related to the version of Ruby (1.8.4) or
that I am running this on Windows XP Pro?

1.8.4?!?

yes. you should update.
 
E

Ehsanul Hoque

I'd like to match a string to another=2C and recognize the match even if th=
ere are a few typing errors. These errors could include omission of a lette=
r/space/punctuation mark=2C an extra letter or a mistyped letter. I don't r=
equire it to detect multiple errors in a row=2C or in a single word. The st=
ring would be comparable to the length of this paragraph=2C a little shorte=
r=2C in case that matters

I could come up with some basic implementation for this=2C but it seems li=
ke a little too much to do for something like this. I was wondering if ther=
e was a simple way to do this=2C a gem perhaps?

Thanks=20
-Ehsan
=0A=
_________________________________________________________________=0A=
Lauren found her dream laptop. Find the PC that=92s right for you.=0A=
http://www.microsoft.com/windows/choosepc/?ocid=3Dftp_val_wl_290=
 
L

Luis Parravicini

I'd like to match a string to another, and recognize the match even if th=
ere are a few typing errors. These errors could include omission of a lette=
r/space/punctuation mark, an extra letter or a mistyped letter. I don't req=
uire it to detect multiple errors in a row, or in a single word. The string=
would be comparable to the length of this paragraph, a little shorter, in =
case that matters
=A0I could come up with some basic implementation for this, but it seems =
like a little too much to do for something like this. I was wondering if th=
ere was a simple way to do this, a gem perhaps?
You could use the Levenshtein distance [1] to check how different is a
string to another. The "Text" [2] gem seems to do that, haven't used
it though.

[1] http://en.wikipedia.org/wiki/Levenshtein_distance
[2] http://raa.ruby-lang.org/project/levenshtein/


--=20
Luis Parravicini
http://ktulu.com.ar/blog/
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Wed, 30 Sep 2009 05:23:15 +0900
Von: Ehsanul Hoque <[email protected]>
An: (e-mail address removed)
Betreff: Match a long string in Ruby despite a few typing errors
I'd like to match a string to another, and recognize the match even if
there are a few typing errors. These errors could include omission of a
letter/space/punctuation mark, an extra letter or a mistyped letter. I don't
require it to detect multiple errors in a row, or in a single word. The string
would be comparable to the length of this paragraph, a little shorter, in
case that matters

I could come up with some basic implementation for this, but it seems
like a little too much to do for something like this. I was wondering if there
was a simple way to do this, a gem perhaps?

Dear Ehsan,

you could use Levenstein distance - there's an implementation in Ruby
here:

http://raa.ruby-lang.org/project/levenshtein/

An even more informative alternative would be using the McIlroy-Hunt longest common subsequence algorithm, of which you get an implementation in the diff-lcs gem.

Both algorithms can be implemented with complexity O(m*n), so this
might take some time, if your string lengths m,n are big.

Maybe you can check beforehand that the lengths of string a and b differ by e.g., 5, so their Levenstein distance is certainly greater than e.g.,
3, which you'd fix as the maximum tolerable error number ...

Also, some tweaking allows to bring down the complexity to O(m+n), as is stated e.g., here : ttp://www.ime.usp.br/~is/papir/sctp/node2.html .

Best regards,

Axel
 
G

Greg Donald

I'd like to match a string to another, and recognize the match even if th=
ere are a few typing errors. These errors could include omission of a lette=
r/space/punctuation mark, an extra letter or a mistyped letter. I don't req=
uire it to detect multiple errors in a row, or in a single word. The string=
would be comparable to the length of this paragraph, a little shorter, in =
case that matters
=A0I could come up with some basic implementation for this, but it seems =
like a little too much to do for something like this. I was wondering if th=
ere was a simple way to do this, a gem perhaps?


Do you know about Soundex?

http://en.wikipedia.org/wiki/Soundex


Looks pretty old but I found this Soundex for Ruby library here:

http://raa.ruby-lang.org/project/soundex/



--=20
Greg Donald
http://destiney.com/
 
M

Michael W. Ryder

Ryan said:
1.8.4?!?

yes. you should update.
I updated to 1.9.1 and now it is complaining that ParseTree does not
work with 1.9.1. Now what do I do?
 
R

Ryan Davis

I'd like to match a string to another, and recognize the match even
if there are a few typing errors. These errors could include
omission of a letter/space/punctuation mark, an extra letter or a
mistyped letter. I don't require it to detect multiple errors in a
row, or in a single word. The string would be comparable to the
length of this paragraph, a little shorter, in case that matters

I could come up with some basic implementation for this, but it
seems like a little too much to do for something like this. I was
wondering if there was a simple way to do this, a gem perhaps?

Don't thread hijack. Start a new mail like a responsible person.
 
R

Ryan Davis

I updated to 1.9.1 and now it is complaining that ParseTree does not
work with 1.9.1. Now what do I do?

ParseTree only works up to 1.8.7. ruby_parser will work for 1.9.x, but
it doesn't work for getting ASTs for procs or other live objects.
 
E

Ehsanul Hoque

Luis=2C Axel and Greg=2C I thank you for your suggestions. The levenshtein =
distance algorithm seems like the way to go=2C and I'll be taking a look at=
the implementations mentioned.

I apologize for hijacking the thread. I didn't realize I was doing this=2C =
I naively assumed threads were based on the subject line=2C which I replace=
d. But apparently not so. It won't happen again in any case.
=0A=
_________________________________________________________________=0A=
Insert movie times and more without leaving Hotmail=AE.=0A=
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=3DTXT_TAGLM_WL_HM_Tut=
orial_QuickAdd_062009=
 
M

Michael W. Ryder

Ryan said:
ParseTree only works up to 1.8.7. ruby_parser will work for 1.9.x, but
it doesn't work for getting ASTs for procs or other live objects.
So my options are:
1. Downgrade to 1.8.7
2. Somehow patch ParseTree to work with 1.9 which seems to be a
f feature request for over a year now.
3. Patch nitpick to work with ruby_parser
4. Forget about using any kind of lint program with Ruby.
Personally I do not like any of the above. I can understand programs
written for version 1.8.7 not working with 1.8.4, but not programs
written for 1.8.7 not working for 1.9.1. Whatever happened to backwards
compatibility?
 
M

Markus Roberts

1.8.4, but not programs written for 1.8.7 not working for 1.9.1.
Whatever happened to backwards compatibility?

You want the most current of the stable branch, not something off of
what is essentially the development branch. 1.9.1. is a major
refactoring, a work in progress towards the eventual 2.x versions.
 
J

John Barnette

Hi,

2. Somehow patch ParseTree to work with 1.9 which seems to be a
f feature request for over a year now.

This will not happen with 1.9 in its current state. It's not a
ParseTree limitation, it's a Ruby 1.9 limitation.


~ j.
 
R

Ryan Davis

So my options are:
1. Downgrade to 1.8.7

yes, that should work.
2. Somehow patch ParseTree to work with 1.9 which seems to be a
f feature request for over a year now.

can't happen, as john pointed out.
3. Patch nitpick to work with ruby_parser

this would probably work fine, but I don't know nitpick so I can only
guess that it is a static-only analysis tool.
4. Forget about using any kind of lint program with Ruby.

not much gray in your world, is there? :p
Personally I do not like any of the above. I can understand
programs written for version 1.8.7 not working with 1.8.4, but not
programs written for 1.8.7 not working for 1.9.1. Whatever happened
to backwards compatibility?

1.9.x does not (nor did it ever intend to) maintain backwards
compatibility with 1.8. Lots of stuff went in 1.9, that's what
progress is for.

See also: perl 4 to perl 5, perl 5 to perl 6, deprecations across java
versions, industrial revolution, ponies.
 
M

Michael W. Ryder

Ryan said:
yes, that should work.


can't happen, as john pointed out.


this would probably work fine, but I don't know nitpick so I can only
guess that it is a static-only analysis tool.


not much gray in your world, is there? :p


1.9.x does not (nor did it ever intend to) maintain backwards
compatibility with 1.8. Lots of stuff went in 1.9, that's what
progress is for.

See also: perl 4 to perl 5, perl 5 to perl 6, deprecations across java
versions, industrial revolution, ponies.
So my best choice is to write my own version of lint using no
dependencies on gems which may be tied to a specific language feature
that may or may not work with the next release of Ruby.
 
J

John Barnette

So my best choice is to write my own version of lint using no
dependencies on gems which may be tied to a specific language
feature that may or may not work with the next release of Ruby.

Wow, drama much? I think the best thing for you to do would be to
focus on the specific problem you're trying to solve (I assume it's "I
need to lint some code!") and any specific problems that are keeping
you from doing it right now (maybe, "It's in 1.9 and nitpick is
jacked!"). Hyperbole is just silly.

Rereading the thread, since nitpick looks to be a static analysis
tool, it seems to me that your "best choice" is to look at modifying
it to use ruby_parser.


~ j.
 
M

Michael W. Ryder

John said:
Wow, drama much? I think the best thing for you to do would be to
focus on the specific problem you're trying to solve (I assume it's "I
need to lint some code!") and any specific problems that are keeping
you from doing it right now (maybe, "It's in 1.9 and nitpick is
jacked!"). Hyperbole is just silly.

The real problem is with the inability to tell if a tool will work in a
given environment. I looked on RubyForge for lint and found two
programs, only one that appeared to be functional. After using gem
install to load the gem and all the dependencies I found out that my
current level of Ruby was insufficient to run the program. So I updated
Ruby to the latest version without knowing that other tools needed by
the first wouldn't work with the latest and greatest. Its very
frustrating to try and do something and spend so much time trying to
navigate the maze of dependencies while blindfolded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,167
Messages
2,570,910
Members
47,453
Latest member
MadelinePh

Latest Threads

Top