mpeterv / luacheck

A tool for linting and static analysis of Lua code.
MIT License
1.91k stars 318 forks source link

custom coding style checker #84

Open houqp opened 7 years ago

houqp commented 7 years ago

Hi,

I am thinking of creating a coding style checker using luacheck for my own project. Since the style guide line is project specific, I think it doesn't make sense to have it included into luacheck. Is it possible to create a custom checker module file that can be loaded by luacheck at runtime?

mpeterv commented 7 years ago

Hi @houqp,

it's not possible at the moment without patching Luacheck. I will look into implementing a plugin system for this, however, it's not obvious how to handle warning code conflicts.

houqp commented 7 years ago

Having a plugin system would be awesome. Looks like warning code are just strings? If so, maybe we can enforce a prefix like x for plugin warning codes?

mpeterv commented 7 years ago

@houqp that works, although different plugins have to use different prefixes.

Another issue: should plugins be configurable? I.e. should they be able to define their own options?

do-you-dare commented 7 years ago

Why not have style check options like rubocop? This way you could enable/disable rules as your style guideline requires.

mpeterv commented 7 years ago

@dread-uo that's basically what I'm trying to do. The problem is that semantics of some luacheck options are fairly convoluted. I can either make defining options for plugins equally convoluted to support them or I can break everything by simplifying what these options do.

do-you-dare commented 7 years ago

Hm... wouldn't it be easier to add new rules directly to luacheck instead of implementing a plugin system? This way you could use your options as they are - maybe refactoring them in the future - and would be easier to integrate on projects, with all the features coming from the same place.

Anyway, a plugin system sounds nice. Breaking up everything for simplicity is a nice idea, if all the options can be simplified. If some of them really benefits from the convolution, you could make defining options for plugins equally convoluted to support them.

If the plugins are custom checker modules, they might have their configuration in them, as well, and in this case you could delegate the configuration process to the plugin.

I'd go with making the plugin system configurable, and slowly incorporating the plugins onto luacheck as they are stable and interesting to have.

houqp commented 7 years ago

configurable builtin style check options like what rubocop has will work for me too as long as I can pick which set of style checks to use for my project.

As for plugin options, I think it's better to keep it simple for now unless necessary. We can always extend it later if other users requested it.

ghost commented 7 years ago

I don't really see why style checking should be part of 'luacheck'. Being a linter, I see its purpose more in checking code for potential bugs, like it currently does really well.

I reckon it makes more sense to have style checking done in a separate tool. That being said, is there already a style checking tool out there? If not, I am happy to start an open-source project, as I am in desperate need of it myself.

mpeterv commented 7 years ago

@tyrondis:

I don't really see why style checking should be part of 'luacheck'. Being a linter, I see its purpose more in checking code for potential bugs, like it currently does really well. I reckon it makes more sense to have style checking done in a separate tool.

Having a single tool both for linting and style checking has its advantages. Each checking tool may do some things other than checking itself: it can apply options, load and apply config file, parse and apply inline options, etc. In a single tool, all this infrastructure is reused across warning types, so that authors don't have to code it twice and users don't have to learn several formats for everything.

That being said, is there already a style checking tool out there?

I don't think there is. I'm adding some trivial style checks to Luacheck but it's not a priority.

If not, I am happy to start an open-source project, as I am in desperate need of it myself.

Good luck!

houqp commented 7 years ago

A lot of the linters has style check builtin. I guess there is no strict definition for what a linter should do. I also think it's not that important as long as we have the tools to get the job done.

As @mpeterv already pointed out, the biggest advantage is code reuse. luacheck already has all the parsing logic with a pluggable API. So it's very natural to extend luacheck for style checks. As a user, I also prefer not having to install yet another tool in my CI and dev environment.

That siad, If you get something working as a new tool, I will definitely give it a try :)