lunarmodules / luacheck

A tool for linting and static analysis of Lua code.
https://luacheck.readthedocs.io
MIT License
359 stars 54 forks source link

Add (optional) rule to check consistency of indentation? #50

Open alexdowad opened 2 years ago

alexdowad commented 2 years ago

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

alerque commented 2 years ago

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.

alexdowad commented 2 years ago

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.

alerque commented 2 years ago

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?

alexdowad commented 2 years ago

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.

alexdowad commented 2 years ago

Or maybe the configuration might be something like this?

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

Or else:

indent_type = 'spaces'
indent_width = 4
CppCXY commented 2 years ago

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

alexdowad commented 2 years ago

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.

ParsaNobahari commented 1 year ago

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

خههههخههالللالللللللل