lunarmodules / luacheck

A tool for linting and static analysis of Lua code.

Home Page:https://luacheck.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add (optional) rule to check consistency of indentation?

alexdowad opened this issue · comments

Thank you for luacheck! It is a very nice tool.

Are you interested in adding a rule to check that indentation is consistent; for example, that only tabs or only spaces are used? Probably this would be disabled by default, to avoid breaking existing users.

If you like the idea, I would be happy to send a PR.

FYA @alerque

Personally I think this is the wrong tool for the job. Conceptually I think a language linter looking for coding errors should completely ignore anything remotely user-preference or style related. Any valid language syntax should be fair game. Separately a different tool (or possible completely different run time mode of a common tool) could look at the coding style and lint, suggest, or just outright format to taste. This would facilitate CI jobs where style vs. syntax and logic issues were treated differently, style was or was not enforced, etc. Also the kind of options that go into what to allow in a language are fundamentally different from what to allow for style (in my view).

Personally for things like enforcing indentation and checking for mixed space/tab usage I use editorconfig rules and editorconfig-checker for linting (other tools like eclint exist too).

That being said there is not another Lua specific tool (or mode) that handles style robustly at this time and there is precedent for whitespace handling rules mixed in the liter (e.g. https://github.com/lunarmodules/luacheck/blob/master/src/luacheck/stages/detect_bad_whitespace.lua) so I guess I don't have solid reason to object to that ruleset being expanded/improved.

Thanks for those thoughtful comments.

If the maintainers want this feature, I am available to help implement it; but if they don't want it, that is fine.

for example, that only tabs or only spaces are used?

Were you thinking this would be a line-wise, file-wise, or project-wise consistency check?

I was thinking that if a user wants to use the check, they would put something in their configuration like:

indent = 'tabs'

...And then luacheck would perform the check on any file it scans.

Or maybe the configuration might be something like this?

indent = { type='spaces', width=4 }

Or else:

indent_type = 'spaces'
indent_width = 4

the EmmyLuaCodeStyle support this feature,it supports the use of language server, lua lib, and command-line tools in three ways

the EmmyLuaCodeStyle support this feature,it supports the use of language server, lua lib, and command-line tools in three ways

Thanks for mentioning that.