0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSHINT option

Last updated at Posted at 2018-04-05

br...fyは特に必要ない。 codemirrorとの相性が良い。

let opt={...};
JSHINT(d,opt);
return JSHINT.data()

option

let opt={browser:true,asi:true,es5:true,esnext:true
,lastsemic:true,laxcomma:true,curly:false,maxdepth:4}

全部

<script src="https://gnjo.github.io/jshint/dist/jshint.js?v1=eeee"></script>
<div f><textarea a></textarea><textarea b></textarea></div>

<style>
 body{margin:0;width:100vw;height:100vh;}
*{background-color:#111;color:#eee;outline:none;resize:none}
[f]{display:flex;height:100%}
textarea{width:50%;padding:0.5rem}
</style>
let fn={}
fn.q=(d=>document.querySelector(d))
fn.sol=(d=>Promise.resolve(d))
;
let a=fn.q('[a]'),b=fn.q('[b]')
,opt={browser:true,asi:true,es5:true,esnext:true,lastsemic:true,laxcomma:true,curly:false,maxdepth:4}
,calc=(d)=>{ JSHINT(d,opt); return JSHINT.data()}
,draw=(d)=>{ b.value=JSON.stringify(d,null,2);return d}
;
a.oninput=function(ev){ fn.sol(this.value).then(calc).then(draw)}
;
console.log(JSHINT)

option参考

https://qiita.com/xorphitus/items/f26ec8fbe17c317d3994
http://yuzuemon.hatenablog.com/entry/2014/11/17/010227

追記 解析結果のエラー判別

let d=JSHINT.data();
if(d.errors) console.log(d.errors)

応用 codemirrorに自分用の設定を適用させ、lintと一緒に使う。

もしcodemirrorと一緒に自分用の設定で使うのであれば公式デモのjavascript-lint.jsをマイグレーションする。
*もっと賢い方法がありそうだけれども。
参考
https://github.com/angelozerr/codemirror-lint-eslint/blob/master/eslint-lint.js

<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.36.0/addon/lint/javascript-lint.js"></script>-->
<script src="https://codepen.io/gnjo/pen/GxzNGz.js?javascriptLintMeJS=001"></script>
//validate()部
...
 var opt={browser:true,asi:true,es5:true,esnext:true,lastsemic:true,laxcomma:true,curly:false,maxdepth:3
     ,unused:true}
  function validator(text, options) {
  ...
    var _o =Object.assign({},options,opt) ;//
    JSHINT(text, _o, _o.globals);
  ...}
}

...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?