Adding my own linter rules


#1

I want to have a rule that warns me when a php file contains style= within any tag. Even alerting on the string ‘style=’ is probably enough.

How do I do that?

I think I want to make custom linter rules.

I have looked for about 1/2 hour and not found a toehold to get started.

I think there must be some wrong with my analysis. So far I have not yet found any file full of rules of any kind.

BTW I use nuclide. I did have to add some config code to convince it that php is not hack, especially for linting purposes. I also know that there may be issues regarding linting so this needs to be taken into account in my solution.


#2

Here’s the documentation for creating linter messages. However, unless you’re already in the business of designing linter packages, I feel like the solution you propose is too much work. It would be a lot faster to use ctrl-shift-f to find all instances of style= in the project.

I’m not aware of any negative interaction between Nuclide and linting, but I don’t use Nuclide.


#3

Would it be possible to add to an existing language package (grammar)?

A dirty way of doing this task would to create a new language package (grammar) from the existing one, and then add an “invalid” colouring to it the style=.

I confess my idea is not as elegant to give an active linter warning.
But at least it can help until a better solution comes.

dP


#4
  1. Thanks for the doc. I think that linting is a place to manage coding style and as such, allow me to constrain or at least counsel regarding undesirable constructs. I eagerly invite statement of a better way.

  2. yes ctrl-F is my friend but I need to get in the faces of other coders on the project who feel free to sneak in inline style which break our project.

  3. I avoided the word negative purposely. nuclide crabs at me about what linter to use or disable. Isn’t negative or positive, technically. Just is an issue, not a huge one, when supporting other coders who don’t want to understand these things and want to know why they can’t just use Coda :slight_smile:


#5

It would, but there’s a strong chance that that would mess up the highlighting given the specific change desired. The whole HTML tag rule set would have to be copied over.

In this case, yes, a linter plugin is what you want.


#6

That is sort of what I intended.
I assumed there was a standard that dictated how I provide what is essentially a ‘local override’ declaring a valid part of the language to be invalid for my team.

I confess this is part of defensive development, when working with a legacy that nobody will let you refactor.


#7

<mood = chatty>
Pre-emptively avoiding future problems

A tough challenge to go against “it was fine like that before you came”. I do not share your field of expertise, but in a way I share a similar crusade.

Like when our electrician wires locally, indifferent to the global machine design. Then one day when he is on holiday, I have fix the machine break-down – starting by bringing the wiring to spec.


<mood = more-or-less-business>
Linting would be perfect for you. What @DamnedScholar provided seems to be the linting messages - push-pull and standard type. Parsing the text buffer would also be needed (guessing). I have looked linter-pydocstyle quickly. I am sure when staring at ./lib/init.coffee long enough, one could understand what to do.

If you work it out and have some “cheat notes” to share, please give me a shout. I would love to use this for a “convert from V1 to V2” project.

Good luck.
-\ Dan