This repository has been archived by the owner on May 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
title: print-concat-semicolon | ||
layout: doc | ||
edit_link: https://github.com/willowtreeapps/wist/edit/master/docs/user-guide/rules/print-concat-semicolon | ||
sidebar: "user-guide" | ||
grouping: "rules" | ||
--- | ||
|
||
# print-concat-semicolon | ||
|
||
Print concatenation must be done with a semicolon. | ||
|
||
## Version | ||
This rule was introduced in Wist 2.0.0. |
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,42 @@ | ||
/** | ||
* When constructing console strings from non-string objects, avoid '+' operator | ||
* which requires objects to be converted to strings first. | ||
* This approach tends to be susceptible to crashes. | ||
* | ||
* @description Print concatenation must be done with a semicolon. | ||
* @since 2.0.0 | ||
*/ | ||
'use strict'; | ||
|
||
module.exports = { | ||
create(context) { | ||
return { | ||
'printStatement:enter': function (ast) { | ||
ast.children.forEach(element => { | ||
let node = element.node; | ||
if (node.context == "expression") { | ||
let concatSymbol = element.children.findFirst(child => child.node.text == "+") | ||
if (concatSymbol != null) { | ||
context.report({ | ||
message: `'+' should not be used in print statements. Consider using a ';' instead.`, | ||
loc: { | ||
start: ast.node.start, | ||
end: ast.node.stop | ||
} | ||
}); | ||
} | ||
console.log(element); | ||
} | ||
}); | ||
// let node = astNode.node; | ||
// context.report({ | ||
// message: `'print' statements should only be used for debugging purposes.`, | ||
// loc: { | ||
// start: node.start, | ||
// end: node.stop | ||
// } | ||
// }); | ||
} | ||
}; | ||
} | ||
}; |