1

I'm the co-founder (there's two of us) of a software development company, doing mostly webdevelopment. Recently we hired our first employee and soon enough we find ourselves in the need of a standard (and preferably enforced) coding style. We do however not enforce a certain IDE. I for example use Atom while the currently other 2 devs use PHPStorm.

Is there a way to enforce a certain coding style, much like you can set in Eclipse, across different editors/IDE's? I know of editorconfig, however that only fixes the indenting-type and end-of-line-characters. Not when to actually use indenting or new-lines. But an extended version of that seems perfect for what we want to achieve.

I haven't been able to find any such thing or any other straightforward way of handling this. How would you go about tackling this?

1
  • 3
    You want code reviews. a coding style is not something that you can enforce by automatic ways (because it also defines conventions). You could however reindent or reformat the code. Sep 16, 2017 at 20:18

1 Answer 1

3

You cannot have a single configuration format that any editor and IDE will understand. Therefore:

  • Define a basic coding convention in plain text. This can evolve over time, and doesn't have to be very detailed in the beginning. Two paragraphs about naming convention and bracing/indentation style is probably sufficient.

  • Everyone is responsible for configuring their own editor in accordance with the coding convention. The editor is an aid for the developer using that editor. Unless you standardize on a single editor/IDE, it is not a suitable platform for other processes.

  • Find a separate style checking and linting tool, and run it as part of your extended test suite. This could run after commit on a CI server, or as a Git pre-commit hook before the ill-formatted code can enter version control.

  • Note that coding conventions will often contain semantic rules that can't be checked by a tool. Human review is important as well. A pull-request based workflow can help that every code is reviewed before it becomes part of your product.

3
  • "You cannot have a single configuration format that any editor and IDE will understand." - You can get pretty close with EditorConfig. There are plugins or tools for Atom, Eclipse, Emacs, jEdit, gEdit, NetBeans, Notepad++, Textmate, vi, Sublime, Visual Studio Code, XCode. It lets you achieve your first point in a programatic way and saves time in implementing your second point. Your third and fourth points are still valid, though - people may not use this tool (or misconfigure it) or you may see things in reviews that cause config changes.
    – Thomas Owens
    Sep 16, 2017 at 20:39
  • @ThomasOwens Yes, using such tools to achieve consistency where possible is sensible. As OP noted EditorConfig in particular only allows for extremely basic configuration. (I also note the lack of support for some editors I've used in the past.) That may or may not be enough to be useful. In my experience, language-specific but editor-agnostic tools tend to be far superior, but I'm probably too strongly influenced by a command-line/Unixy approach.
    – amon
    Sep 16, 2017 at 21:00
  • +1 for backing it up with another linting tool that handles the enforcement.
    – Paul
    Sep 17, 2017 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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