Search code examples
javascriptpythoneslintvisual-studio-codepep8

How to set a default linter to be used across various IDEs


This might be super simple but I'm not sure how to word this to effectively google.

I am looking to set a default code style / linter to my python/flask/JavaScript project. I have people working with different IDEs, so sometimes code thats well formatted on VSCode, gets flagged differently on PyCharm.

Is there some sort of settings file that I can create that will cause any IDE to read it and use a set linter? I googled around and only found people setting their linter through their IDEs

Im hoping to use PEP8 for python and havent decided on a JavaScript linter.


Solution

  • Is there some sort of settings file that I can create that will cause any IDE to read it and use a set linter?

    No, there is no one solution that covers all IDEs and all linters. The most popular lint tools do have cross-platform instructions for the most popular editors that describe how to make the most of them, though.

    Standardized scripts

    Scripts can be specified to execute a specific shared linter that everyone is assumed to have; for example, a Javascript project's package.json may have a lint script that runs eslint and installs eslint in devDependencies, and a project-specific eslint config file can be committed to version control so everyone has the same configuration. (The same is true for test frameworks, formatting utilities, or anything else.)

    If everyone's IDE (or local build chain, or precommit hook, etc.) is configured to execute npm run lint or make lint or similar rather than some native/proprietary tool, then you've succeeded in specifying a default. These choices be checked in to source control and be made consistent and available for everyone; the challenge is making sure other devs' environments respect this default.

    Standardized plugins and plugin settings

    Some IDE extensions, like ESLint for VSCode (dbaeumer.vscode-eslint), will look at your environment and automatically run appropriate tools for you; some operate while typing, on save, on build, or on commit. Some of these may not use your package/module/project metadata, instead looking for the presence of a tool and its config (e.g. eslint in PATH or node_modules and an .eslint.json or similar in your project directory). By committing IDE extension configuration with your code, such as .vscode/extensions.json, a few unrelated IDEs can have their linting behavior shared with the assistance of customizable editors and their add-ons.

    Note that transformative tools, like black for Python, are in a slightly different category; many linters can be configured to automatically correct some issues and behave almost like a formatter, but you may be conflating formatting and linting in your question, so just be aware of the distinction.

    P.S. Reproducible and predictable dev environments have been a common concern for a very long time, and there are literally hundreds or thousands of solutions nowadays. Some teams still share development VMs/containers à la vagrant and docker; some teams use cloud IDEs or file shares to synchronize prescribed settings to every dev machine; and most maintain a wiki article or README file documenting the steps to set up one's own environment to conform to a team's expectations.