Skip to content
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

Enable LuaCheck to report common whitespace issues #81

Merged
merged 7 commits into from
Nov 15, 2016

Conversation

n1tehawk
Copy link
Contributor

See #79

@mpeterv
Copy link
Owner

mpeterv commented Nov 15, 2016

Thank you for your work! I'll post some comments now, let me know if you want me to merge this as is and tweak things myself.

@@ -33,7 +33,7 @@ script:
- lua -e 'package.preload.lanes=error;package.path="./src/?.lua;./src/?/init.lua;"..package.path' -lluacov bin/luacheck.lua --version | grep 'Not found'
- lua install.lua path/to/luacheck
- mv src src2
- path/to/luacheck/bin/luacheck spec/*.lua
- path/to/luacheck/bin/luacheck spec/*.lua --ignore 612
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for that one long string literal in a test, right? It would be better to ignore this warning specifically using inline options ("-- luacheck: ignore 612").


function inconsistent_indentation()
return "Don't do this"
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file shouldn't produce unrelated warnings. Functions can be made fields of a local table which is returned at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I had tried local functions, but overlooked the obvious solution of returning a "module" table.


it("detects whitespace issues", function()
local warnings = check(
io.open("spec/samples/bad_whitespace.lua", "rb"):read("*a")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests in check_spec mostly operate on strings. Checks on files go into cli_spec, where error messages are also tested.

@n1tehawk
Copy link
Contributor Author

I'm fine with correcting these myself, if you don't mind me force-pushing a bit to this branch. I'll let you know when I consider it 'final' for merging.

Otherwise LuaCheck would now FAIL its self-test. :D

Note: spec/lexer_spec.lua contains a trailing space that is to be
kept. Add an "inline" option so that LuaCheck won't complain there.
While at it, fix samples file count for cli_spec.lua accordingly.
This explicitly checks for the expected warnings, and improves code
coverage during the "busted -c" run.
@n1tehawk
Copy link
Contributor Author

Done. You may review and/or merge now...

Regards, NiteHawk

@mpeterv
Copy link
Owner

mpeterv commented Nov 15, 2016

Merging, thanks! I plan to make a new release within a week.

@mpeterv mpeterv merged commit 0c6cdc7 into mpeterv:master Nov 15, 2016
@n1tehawk n1tehawk deleted the check_whitespace branch November 15, 2016 16:31
@n1tehawk
Copy link
Contributor Author

n1tehawk commented Nov 15, 2016

Great. 😃

The documentation needs to be updated accordingly. If you want me to, I'm happy to help with that (assuming that it would mainly affect warnings.rst?).

Regards, NiteHawk

@mpeterv
Copy link
Owner

mpeterv commented Nov 15, 2016

Yes, that would only affect warnings.rst. If you want to do that, just add the two three new warnings to the table and add a section at the bottom saying that luacheck also detects some whitespace issues.

@n1tehawk
Copy link
Contributor Author

Shouldn't we mention the "long string literals" issue (as a caveat), and that it may require an (inline) ignore?

@mpeterv
Copy link
Owner

mpeterv commented Nov 15, 2016

I don't think we should, I'd rather open an issue for it.

@n1tehawk
Copy link
Contributor Author

You may cherry-pick from n1tehawk@9c3280b. Or want me to create another PR for it?

@mpeterv
Copy link
Owner

mpeterv commented Nov 15, 2016

I'll cherry-pick it, thanks!

@justinmk
Copy link

Since this was merged we're seeing an error like this:

No LuaRocks module found for luacheck.whitespace

Is this because we need to wait for luarocks to get an updated luacheck package?

Our fault for not pinning to a specific version, of course--just wondering if this is expected. Thanks!

@n1tehawk
Copy link
Contributor Author

n1tehawk commented Nov 16, 2016

I had modified the .rockspec in the repo to include the new sourcefile - a local test with luarocks make luacheck-scm-1.rockspec produces the expected results for me. And the 'stable' 0.16.3-1 should not reference this file, so I'm a bit puzzled as to why you are seeing this error.

Are you building from a scm .rockspec "out there" in the rocks repositories? That might actually lack behind, and if it causes the build to retrieve 'fresh' files from GitHub for the outdated set of files (i.e. not including whitespace.lua), then check.lua will reference a 'non-existent' file...

Regards, NiteHawk

@n1tehawk
Copy link
Contributor Author

n1tehawk commented Nov 16, 2016

I have restarted a Travis build for a project that uses Luacheck via the standard luarocks install luacheck - seems to be fine: https://travis-ci.org/n1tehawk/luaunit/builds/175469291 (still using 0.16.3-1)

@mpeterv
Copy link
Owner

mpeterv commented Nov 16, 2016

@justinmk if you really want to use bleeding-edge version you should get the rockspec from master branch, not a fixed commit, like neovim does now. (And the correct way to install from a specific commit is cloning that commit and running "luarocks make" from project directory.) The reason is that running "install" or "build" on an scm rockspec fetches sources from master but uses build description from the rockspec itself, which may be outdated. I would recommend pinning the version or at least installing latest release though.

@justinmk
Copy link

@mpeterv That makes sense, thanks a lot.

justinmk added a commit to justinmk/neovim that referenced this pull request Nov 16, 2016
mpeterv/luacheck#81 (comment)

> If you really want to use bleeding-edge version you should get the
> rockspec from master branch, not a fixed commit ...
> The correct way to install from a specific commit is cloning that
> commit and running "luarocks make" from project directory. The reason
> is that running "install" or "build" on an scm rockspec fetches
> sources from master but uses build description from the rockspec
> itself, which may be outdated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants