2

I'm heading a new team of developers working on a software project that makes use of continuous integration (circleci) w/ a pretty fleshed out suite of busterjs unit/integration/acceptance tests. Our project is primarily written w/ coffeescript, and I try to make use of coffeescript-linter to ensure everyone working our code base keeps code consistent and as organized as possible.

My question is, does anyone have any thoughts on when/if/how to enforce linting? Should I integrate linting into my tests that are executed by circleci before deployment?

Another thought I had was writing a simple shell script that combines git-push and the linting utility into one step and then including it in the project & having everyone use it.

I'm pretty new to managing teams of programmers so anyone else's feedback is much appreciated.

EDIT: In the last 3 seconds it just occurred to me that git-hooks is probably perfect for this. Specifically a git-hook on commit.

2
  • 1
    When to enforce? Immediately. But I'm not sure you need automated enforcement; code style doesn't affect functionality. Just carry around a big stick, and whack the ones who refuse to comply. Apr 2, 2013 at 17:47
  • Yeah I'm debating doing it at all. Don't want to burden my team with trivial requirements & let them focus on more important things like functionality and deadlines. That being said consistency sometimes aids in maintainability & readability between programmers Apr 2, 2013 at 17:49

4 Answers 4

7

When you a) have a coding standard and b) have configured the linter to be consistent with the coding standard, that's when you start enforcing linting.

Put the linter on the CI server.

1
  • I'd even suggest having a successful lint run as a part of the checkin trigger maybe. Allow for a mechanism for explicitly declaring exceptions though.
    – Rob Wells
    Aug 27, 2013 at 9:52
3

The question is, how important is it to you that issues found by coffeescript-linter are addressed immediately.

If it is unacceptable to have code in the repository that gets flagged by the linter, then you should have the linter run as a commit hook so it can block the commit if there are issues.

If it is undesirable but not unacceptable, then I would run the linter as part of the test suite (and it it complains, regard that as a test failure)

If it is not practical to run the linter as a test case, then I would run it on the CI server on a separate schedule (for example, once a day or once a week) and encourage developers to use the linter when they have a particularly large commit.

2
  • Totally agree with the first three paragraphs. Not sure about the last one though @Bart. I've seen a lot of technical debt pile up in projects where successful lint runs where required... eventually. Unless a cleanup is regularly enforced, you finish up with a massive stack of "to do's" that people are afraid to touch because their system is currently working "as is". (-:
    – Rob Wells
    Aug 27, 2013 at 9:56
  • @RobWells: Of course it is best to integrate the lint with the build, but sometimes it is just not practical. What if every commit kicks of a build, but the build server builds up a backlog due to the duration of build+lint? Aug 27, 2013 at 16:14
0

The team I work with is very strict with linting - the helpfulness of that is something I can't understate.

Unfortunately, git has no way to enforce linting. Even if it did, enforcing the correct version of the linting tool, enforcing the same configuration etc would still be a problem.

So this was our solution:

  1. Our lint configurations are committed - and changes heavily scrutinised in code review. This keeps them in sync.
  2. The lint runs on the CI server. This CI plan should never fail - and when it does, the culprit's name (ie, the last to commit) comes up in big red letters in our group chat.
  3. In light of the above, it is in the interest of our programmers to prevent it from happening by making sure their git hooks are working correctly.

It works very well for us, Once programmers get into the habit even the linters don't really hold them up, as they'll just eventually write in the enforced style. Until then, expect them to be cursing at the computer and whining about how long it takes them to do things. It doesn't actually affect them that much, but it can feel like it when running down a long list of things that are "wrong".

0

As you commented already on your own, I think it is most important that the team carries the decision that successful linting should be required.

I'm a big fan of static code analysis. I once managed to enforce a similar thing in the backend ("Treat Warnings As Errors" in C#) in an organization across several teams. At least some aspects of this were questioned over and over again (mostly because of technical shortcomings).

If some team members are really uncomfortable with the overhead incurred by continuous linting, the better solution can be to deactivate (parts of) it. Sometimes having all team members on the same page is more important than a cleaner code base.

Not the answer you're looking for? Browse other questions tagged or ask your own question.