-
-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: console.log(式); //=> 評価結果
に表記を統一
#212
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d435c0e
refactor: `console.log(式); //=> 評価結果` に表記を統一
azu e222f1d
refactor(operator): console.logを使うように
azu 49d7974
Revert "refactor(operator): console.logを使うように"
azu b0fd270
fix(test): Identifierを含んでいるかを判定に追加
azu 7637ab4
refactor(data-type): リテラルからはconsole.logを削除
azu 7a488fa
docs(CONTRIBUTING): どちらを優先するかを記述
azu eca1f33
test(comment): 1行以下のもおんはチェックしないように
azu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// MIT © 2017 azu | ||
"use strict"; | ||
const esprima = require("esprima"); | ||
const esquery = require("esquery"); | ||
const path = require("path"); | ||
const ignoreFileList = [ | ||
// 演算子はいいかな | ||
"source/basic/operator", | ||
// これもリテラルの話なので… | ||
"source/basic/implicit-coercion" | ||
]; | ||
/** | ||
* 変数を含んでいるか | ||
* @param {Object} AST | ||
* @returns {boolean} | ||
*/ | ||
const isIncludeVariableInExpression = (AST) => { | ||
// 例外 | ||
// call({ x : 1}) | ||
const Identifiers = esquery(AST, "*:not(Property) Identifier"); | ||
if (Identifiers.length > 0) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* コードで `評価式; // => 評価値` を利用している箇所で | ||
* `console.log`を付けるかどうかを判定する | ||
* https://github.com/asciidwango/js-primer/issues/195 | ||
* | ||
* - 基本的にはconsole.logを利用する | ||
* - リテラルや変数が登場しないコードでは`console.log`を省いても良い | ||
* | ||
* lineが問題ある行ならばErrorオブジェクトを返す | ||
* @param {string} text | ||
* @param {string} filePath ファイルパスは無視したい対象の指定に使う | ||
* @returns {Error|undefined} | ||
*/ | ||
module.exports = function shouldConsoleWithComment(text, filePath) { | ||
const lines = text.split("\n"); | ||
// 1行以下なら無視する | ||
if (lines.length <= 1) { | ||
return; | ||
} | ||
lines.forEach(line => { | ||
const error = checkLineThatShouldHaveComment(line, filePath); | ||
if (error instanceof Error) { | ||
throw error; | ||
} | ||
}); | ||
}; | ||
/** | ||
* @param {string} line | ||
* @param {string} filePath | ||
* @returns {Error|undefined} | ||
*/ | ||
function checkLineThatShouldHaveComment(line, filePath) { | ||
if (!/\/\/\s*=>\s*/.test(text)) { | ||
return; | ||
} | ||
if (text.includes("console.")) { | ||
return; | ||
} | ||
// エラーの場合は無視 | ||
if (/=>.*Error/.test(text)) { | ||
return; | ||
} | ||
// template literalっぽいのは無視 | ||
if (text.includes("`")) { | ||
return; | ||
} | ||
|
||
const AST = esprima.parse(text); | ||
// 変数を含まないリテラルのみであるならパスする | ||
if (!isIncludeVariableInExpression(AST)) { | ||
return; | ||
} | ||
// 無視リストに含まれているなら無視 | ||
const isIgnored = ignoreFileList.some(ignoreFilePath => { | ||
return filePath.includes(path.normalize(ignoreFilePath)); | ||
}); | ||
if (isIgnored) { | ||
return; | ||
} | ||
return new Error(`console.log(式); // => 評価結果 にそろえてください | ||
該当コード: ${text}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これも不要っぽい
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
と思ったけど値として返ってくるという話なのであったほうがいいか