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

**URL:** <https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054>\
**Category:** Support\
**Created:** [July 17, 2019, 5:10pm UTC](https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054 "2019-07-17T17:10:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalitbit](https://avatars.discourse-cdn.com/v4/letter/l/ac8455/32.png) [@lalitbit](https://forum.openzeppelin.com/u/lalitbit)\
**Post date:** [July 17, 2019, 5:10pm UTC](https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054/1 "2019-07-17T17:10:41Z")

</div>

I am using truffle with VS Code IDE to build and smart contract. Currently i can run Linter via command (run on console), I am wondering if i can run automate this and run linter command before compile/migrate, and it fails if there is any linter issues.

---

<div class="post-metadata">

**Author:** ![Skyge](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/skyge/32/343_2.png) [@Skyge](https://forum.openzeppelin.com/u/Skyge)\
**Post date:** [July 17, 2019, 10:10pm UTC](https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054/2 "2019-07-17T22:10:46Z")

</div>

Welcome to community!  
I think this is depends on how you set for your config of the Linter.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 18, 2019, 2:38am UTC](https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054/3 "2019-07-18T02:38:03Z")

</div>

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.

> [@Test smart contracts like a rockstar](https://forum.openzeppelin.com/t/test-smart-contracts-like-a-rockstar/1001):
>
> [One does not simply](https://pics.me.me/one-does-not-simply-five-oh-my-god-thats-awesome-work-11532882.png) test your dapp. Among many other things while developing a decentralized application, testing it is something you always need to do. What most people still don’t do is automate those tests, which leads to a huge loss of time and drains the energy to code. Automated tests have been around for a while and they have been gaining lots of traction in the last decade. Whilst blockchain and smart contract development are fairly new, we can still automate tests for these. We can, s…

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.

> [@VSC extension recommendations](https://forum.openzeppelin.com/t/vsc-extension-recommendations/606/4):
>
> I find Juan Blanco’s extension a must if you are using VSCode for anything Ethereum. Apart from it, I also use: EditorConfig for VS Code and Prettier extensions for code formatting. Mocha sidebar to run tests. Note that this one doesn’t work with Truffle, but I use it for dapps’ code and [Buidler](https://buidler.dev/) tests.

You could add a [script](https://docs.npmjs.com/cli/run-script) to `package.json` such as the example compile below, which first runs lint and then compiles.

```auto
  "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](https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/package.json) scripts.

---

<div class="post-metadata">

**Author:** ![abcoathup](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/abcoathup/32/415_2.png) [@abcoathup](https://forum.openzeppelin.com/u/abcoathup)\
**Post date:** [July 22, 2019, 9:02am UTC](https://forum.openzeppelin.com/t/truffle-how-to-run-linter-command-before-compile-or-migrate/1054/4 "2019-07-22T09:02:16Z")

</div>

Hi @lalitbit  
How did you get on Linting before compiling?

If the above reply solved your issue can you mark it as the solution, otherwise please ask more questions.
