Skip to content

Instantly share code, notes, and snippets.

@sanemat
Last active August 29, 2015 14:15
Show Gist options
  • Save sanemat/5416e4f701922a47773a to your computer and use it in GitHub Desktop.
Save sanemat/5416e4f701922a47773a to your computer and use it in GitHub Desktop.
lintとか #tng15

Lint for JavaScript

  • eslint
  • jscs
  • jshint
  • jslint
  • Closure Linter
  • coffeelint
  • tslint

lintにかかわらず、こういう開発便利系何使ってる? 何知ってる?

pronto

で、pronto gemってのがある Ruby

これjsのutilも使いたい

pronto-jshint を参照しよう! -> jshintrb ??? イマココ

↓みたいな感じにしたい

pronto pick-patch | any-command | pronto github_pr

For Ruby

  • rubocop
  • brakeman
  • rails best practice

Web service

  • hound-ci
@sanemat
Copy link
Author

sanemat commented Feb 13, 2015

https://github.com/jquery/esprima
有用な奴の宝庫っぽい

 "scripts": {
        "generate-regex": "node tools/generate-identifier-regex.js",

        "test": "node test/run.js && npm run lint && npm run coverage",

        "lint": "npm run check-version && npm run eslint && npm run jscs && npm run complexity",
        "check-version": "node tools/check-version.js",
        "jscs": "jscs esprima.js test/*test.js",
        "eslint": "node node_modules/eslint/bin/eslint.js esprima.js",
        "complexity": "node tools/list-complexity.js && cr -s -l -w --maxcyc 16 esprima.js",

        "coverage": "npm run analyze-coverage && npm run check-coverage",
        "analyze-coverage": "node node_modules/istanbul/lib/cli.js cover test/runner.js",
        "check-coverage": "node node_modules/istanbul/lib/cli.js check-coverage --statement 100 --branch 100 --function 100",

        "benchmark": "node test/benchmarks.js",
        "benchmark-quick": "node test/benchmarks.js quick"

@sanemat
Copy link
Author

sanemat commented Feb 13, 2015

eslint format(from esprima examples)

$ node node_modules/eslint/bin/eslint.js --format stylish examples/tokendist.js

examples/tokendist.js
  21:18  error  Unexpected sync method: 'readFileSync'  no-sync
  31:8   error  Unexpected console statement            no-console

✖ 2 problems

$ node node_modules/eslint/bin/eslint.js --format compact examples/tokendist.js
examples/tokendist.js: line 21, col 18, Error - Unexpected sync method: 'readFileSync'. (no-sync)
examples/tokendist.js: line 31, col 8, Error - Unexpected console statement. (no-console)

2 problems

$ node node_modules/eslint/bin/eslint.js --format checkstyle examples/tokendist.js
<?xml version="1.0" encoding="utf-8"?><checkstyle version="4.3"><file name="examples/tokendist.js"><error line="21" column="18" severity="error" message="Unexpected sync method: &apos;readFileSync&apos;. (no-sync)" /><error line="31" column="8" severity="error" message="Unexpected console statement. (no-console)" /></file></checkstyle>

$ node node_modules/eslint/bin/eslint.js --format jslint-xml examples/tokendist.js
<?xml version="1.0" encoding="utf-8"?><jslint><file name="examples/tokendist.js"><issue line="21" char="18" evidence="fs.readFileSync" reason="Unexpected sync method: &apos;readFileSync&apos;. (no-sync)" /><issue line="31" char="8" evidence="console.log" reason="Unexpected console statement. (no-console)" /></file></jslint>

$ node node_modules/eslint/bin/eslint.js --format junit examples/tokendist.js
<?xml version="1.0" encoding="utf-8"?>
<testsuites>
<testsuite package="org.eslint" time="0" tests="2" errors="2" name="examples/tokendist.js">
<testcase time="0" name="org.eslint.no-sync"><failure message="Unexpected sync method: &apos;readFileSync&apos;."><![CDATA[line 21, col 18, Error - Unexpected sync method: &apos;readFileSync&apos;. (no-sync)]]></failure></testcase>
<testcase time="0" name="org.eslint.no-console"><failure message="Unexpected console statement."><![CDATA[line 31, col 8, Error - Unexpected console statement. (no-console)]]></failure></testcase>
</testsuite>
</testsuites>

$ node node_modules/eslint/bin/eslint.js --format tap examples/tokendist.js
TAP version 13
1..1
not ok 1 - examples/tokendist.js
  ---
  message: "Unexpected sync method: 'readFileSync'."
  severity: error
  data:
    line: 21
    column: 18
    ruleId: no-sync
  messages:
    - message: Unexpected console statement.
      severity: error
      data:
        line: 31
        column: 8
        ruleId: no-console
  ...

@sanemat
Copy link
Author

sanemat commented Feb 13, 2015

eslintの場合 checkstyle, jslint-xml がparseしやすい

@sanemat
Copy link
Author

sanemat commented Feb 13, 2015

@sanemat
Copy link
Author

sanemat commented Feb 13, 2015

rubocop とrubocop-checkstyle_formatter, file nameがフルパスだ

$ rubocop --require rubocop/formatter/checkstyle_formatter --format RuboCop::Formatter::CheckstyleFormatter lib/github_api.rb
<?xml version='1.0'?>
<checkstyle>
  <file name='/Users/sane/work/tachiko/pigeon.tachikoma.io/lib/github_api.rb'>
    <error line='4' column='0' severity='info' message='Class definition is too long. [164/100]' source='com.puppycrawl.tools.checkstyle.Metrics/ClassLength'/>
    <error line='42' column='2' severity='info' message='Method has too many lines. [11/10]' source='com.puppycrawl.tools.checkstyle.Metrics/MethodLength'/>
    <error line='52' column='4' severity='info' message='Favor modifier `unless` usage when having a single-line body. Another good alternative is the usage of control flow `&amp;&amp;`/`||`.' source='com.puppycrawl.tools.checkstyle.Style/IfUnlessModifier'/>
    <error line='82' column='2' severity='info' message='Assignment Branch Condition size for fork_from_this is too high. [22.65/15]' source='com.puppycrawl.tools.checkstyle.Metrics/AbcSize'/>
    <error line='82' column='2' severity='info' message='Method has too many lines. [12/10]' source='com.puppycrawl.tools.checkstyle.Metrics/MethodLength'/>
    <error line='187' column='2' severity='info' message='Method has too many lines. [11/10]' source='com.puppycrawl.tools.checkstyle.Metrics/MethodLength'/>
  </file>
</checkstyle>

@sanemat
Copy link
Author

sanemat commented Feb 15, 2015

errorなしだとこんな出力になる

<?xml version='1.0'?>
<checkstyle>
  <file name='/Users/sane/work/tachiko/pigeon.tachikoma.io/Rakefile'/>
</checkstyle>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment