Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make Linting Great Again (Long version)

Make Linting Great Again (Long version)

Presented at Agent Conf 2018

Andrey Okonetchnikov

January 25, 2018
Tweet

More Decks by Andrey Okonetchnikov

Other Decks in Programming

Transcript

  1. –Wikipedia “lint or a linter is any tool that flags

    suspicious usage in software written in any computer language.”
  2. Using linters & formatters leads to 1. Fewer (stupid) bugs

    2. Better readability => less time in code reviews 3. But it can slow you down… :(
  3. git hooks are 1. Hard to setup 2. Hard to

    manage 3. Hard to share across the team
  4. Thanks husky! 1. Hard to setup 2. Hard to manage

    3. Hard to share across the team
  5. …but linting the whole project 1. Can be quite slow

    2. Will display irrelevant results
  6. git hooks are 1. Hard to setup 2. Hard to

    manage 3. Hard to share across the team 4. Very slow 5. Displaying irrelevant results A WES OME!
  7. #!/bin/bash executable=$(npm bin)/staged-files linter_name="eslint" linter_path=$(npm bin)/eslint lint_extensions="**/*.@(js|jsx)" if [[ -f

    "${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
  8. #!/bin/bash executable=$(npm bin)/staged-files linter_name="stylelint" linter_path=$(npm bin)/stylelint lint_extensions="**/*.@(css|scss|less|styl)" if [[ -f

    "${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
  9. #!/bin/bash executable=$(npm bin)/staged-files linter_name="flow" linter_path=$(npm bin)/flow lint_extensions="**/*.@(js|jsx)" if [[ -f

    "${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install ${linter_name}-bin" fi
  10. #!/bin/bash executable=$(npm bin)/staged-files linter_name="jscs" linter_path=$(npm bin)/jscs lint_extensions="**/*.@(js|jsx)" if [[ -f

    "${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
  11. DRY

  12. lint-staged is a tool that • Can run any task

    • Easy to install via npm • Easy to distribute across the team (.lintstagedrc) • Easy to use (DX!)