Truffle - How to run Linter command before compile or migrate?

Hi @lalitbit welcome.

As per @skyge the answer is it depends.
Some of the potential options are as follows (though @skyge may have a better solution):

You could look at doing linting as part of Continuous Integration.

I use Juan Blanco's Solidity extension, so that in VS Code I get errors and warnings about my Solidity formatting and then use linting to catch anything I have missed.

You could add a script to package.json such as the example compile below, which first runs lint and then compiles.

  "scripts": {
    "compile": "npm run lint && truffle compile",
    "coverage": "solidity-coverage && cat coverage/lcov.info | coveralls",
    "lint": "npm run lint:js && npm run lint:sol",
    "lint:fix": "npm run lint:js:fix",
    "lint:js": "eslint .",
    "lint:js:fix": "eslint . --fix",
    "lint:sol": "solhint --max-warnings 0 \"contracts/**/*.sol\"",
    "test": "truffle test"
  },

This is based on the OpenZeppelin package.json scripts.

1 Like