Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
AtsushiM committed Dec 18, 2012
1 parent f2a6d22 commit 2b75bad
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 2 deletions.
14 changes: 13 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ jslint, gjslintとの併用をおすすめします。
・1ファイル50行以内(小クラス主義)
・1ファイル内でvar宣言は5個(クラスが持ち得る状態のパターンを減らす)
・1行で使える.(ドット)は3個(なるべく直接のプロパティにのみアクセスすることで分かりやすさを向上)
・1ファイル中のifは5個(ifを少なくすることでのネストの排除 & 少クラス化の促進)
・1ファイル中のifは5個(ifを少なくすることでのネストの排除 & 小クラス化の促進)
・1ファイル中のelseは1個(elseを少なくすることで早期returnの推奨)
・1ファイル中のswitchは1個(switchを少なくすることで小クラス化の促進)
・1ファイル中のforは3個(forを少なくすることでネストの排除 & 小クラス化の促進)
・1ファイル中のwhileは3個(whileを少なくすることでネストの排除 & 小クラス化の促進)
・1ファイル中のdoは1個(doの使用を制限)
・1ファイル内の無名関数は5個(1クラスあたりのメソッドの個数を制限し小クラス化を促進)
・1ファイル内の名前付き関数は5個(メンバ関数の乱立を抑止)

Expand Down Expand Up @@ -49,6 +52,15 @@ let g:oopjs_elselimitnum = 1
" 1ファイル中で使えるswitchの個数
let g:oopjs_switchlimitnum = 1

" 1ファイル中のforの個数
let g:oopjs_forlimitnum = 3

" 1ファイル中のwhileの個数
let g:oopjs_whilelimitnum = 3

" 1ファイル中のdoの個数
let g:oopjs_dolimitnum = 1

" 1ファイル内の無名関数の個数
let g:oopjs_anonymousfunctionlimitnum = 5

Expand Down
71 changes: 70 additions & 1 deletion autoload/oopjs.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let s:save_cpo = &cpo
set cpo&vim

if !exists("g:oopjs_ignorecheckfile")
let g:oopjs_ignorecheckfile = ['min\.js', 'combine\.js', 'lib\/.\+\.js']
let g:oopjs_ignorecheckfile = ['test\.js', 'min\.js', 'combine\.js', 'lib\/.\+\.js']
endif
if !exists("g:oopjs_linelimitnum")
let g:oopjs_linelimitnum = 50
Expand All @@ -27,6 +27,15 @@ endif
if !exists("g:oopjs_switchlimitnum")
let g:oopjs_switchlimitnum = 1
endif
if !exists("g:oopjs_forlimitnum")
let g:oopjs_forlimitnum = 3
endif
if !exists("g:oopjs_whilelimitnum")
let g:oopjs_whilelimitnum = 3
endif
if !exists("g:oopjs_dolimitnum")
let g:oopjs_dolimitnum = 1
endif
if !exists("g:oopjs_anonymousfunctionlimitnum")
let g:oopjs_anonymousfunctionlimitnum = 5
endif
Expand All @@ -52,6 +61,9 @@ function! oopjs#Check()
call oopjs#ifCheck(errors)
call oopjs#elseCheck(errors)
call oopjs#switchCheck(errors)
call oopjs#forCheck(errors)
call oopjs#whileCheck(errors)
call oopjs#doCheck(errors)
call oopjs#anonymousfunctionCheck(errors)
call oopjs#namedfunctionCheck(errors)

Expand Down Expand Up @@ -185,6 +197,63 @@ function! oopjs#switchCheck(errors)
let linenum = linenum + 1
endfor
endfunction
function! oopjs#forCheck(errors)
let errors = a:errors
let js = readfile(expand('%'))
let linenum = 1
let cnt = 0

for e in js
if matchlist(e, '\vfor(\s*)\(') != []
let cnt = cnt + 1

if cnt > g:oopjs_forlimitnum
let errors = add(errors, expand('%').':'.linenum.':for <= '.g:oopjs_forlimitnum)
break
endif
endif

let linenum = linenum + 1
endfor
endfunction
function! oopjs#whileCheck(errors)
let errors = a:errors
let js = readfile(expand('%'))
let linenum = 1
let cnt = 0

for e in js
if matchlist(e, '\vwhile(\s*)\(') != []
let cnt = cnt + 1

if cnt > g:oopjs_whilelimitnum
let errors = add(errors, expand('%').':'.linenum.':while <= '.g:oopjs_whilelimitnum)
break
endif
endif

let linenum = linenum + 1
endfor
endfunction
function! oopjs#doCheck(errors)
let errors = a:errors
let js = readfile(expand('%'))
let linenum = 1
let cnt = 0

for e in js
if matchlist(e, '\vdo(\s*)\{') != []
let cnt = cnt + 1

if cnt > g:oopjs_dolimitnum
let errors = add(errors, expand('%').':'.linenum.':do <= '.g:oopjs_dolimitnum)
break
endif
endif

let linenum = linenum + 1
endfor
endfunction

function! oopjs#dotCheck(errors)
let errors = a:errors
Expand Down
101 changes: 101 additions & 0 deletions test/check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var a = 0;
var b = 1;
var c = 2;
var d = 3;
var e = 4;
var f = 5;

a = t.e.s.t.e.s.t;

(function() {}());
(function() {}());
(function() {}());
(function() {}());
(function() {}());
(function() {}());

function _a() {
}
function _b() {
}
function _c() {
}
function _d() {
}
function _e() {
}
function _f() {
}

if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
else {
_b();
}
if (1 === 1) {
_a();
}
if (1 === 1) {
_a();
}
else {
_b();
}
if (1 === 1) {
_a();
}
else if (2 === 2) {
_b();
}

switch (a) {
default:
break;
}
switch (a) {
default:
break;
}

for () {
}
for () {
}
for () {
}
for () {
}

while () {
}
while () {
}
while () {
}
while () {
}

do {
}
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ switch (a) {
default:
break;
}

for () {
}
for () {
}

while () {
}
while () {
}

do {
}
while ();

0 comments on commit 2b75bad

Please sign in to comment.