Skip to content

Commit

Permalink
v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
zengxiaoluan committed Jul 12, 2024
1 parent 257c79a commit 716abf1
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
16 changes: 16 additions & 0 deletions docs/rules/comments-need-space.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ function hello() {
// comments
}
```

Comments like below is not ok:

```js
function hello() {
// comments中英文混杂没有空格
}
```

That is good:

```js
function hello() {
// comments 中英文混杂有空格
}
```
14 changes: 14 additions & 0 deletions docs/rules/prefer-template-literal.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Prefer template literal (`jlc/prefer-template-literal`)

<!-- end auto-generated rule header -->

That is bad:

```js
const name = "tom";
const message = "Hello" + name;
```

That is good:

```js
const name = "tom";
const message = `Hello ${name}`;
```
17 changes: 16 additions & 1 deletion lib/rules/comments-need-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
schema: [], // Add a schema if the rule has options
messages: {
needSpace: "comments need space",
spaceWithEnZh: "Need space between english and chinese",
}, // Add messageId and message
},

Expand All @@ -41,12 +42,26 @@ module.exports = {
// visitor functions for different types of nodes
Program(node) {
for (const comment of node.comments || []) {
if (comment.type === "Line" && !comment.value.startsWith(" ")) {
let value = comment.value;

if (comment.type === "Line" && !value.startsWith(" ")) {
context.report({
loc: comment.loc,
messageId: "needSpace",
});
}

let matches = value.match(/(\w[^\w\s'"])/g) || [];

for (const item of matches) {
let maxAsciiCode = 128;
if (item.length === 2 && item.charCodeAt(1) > maxAsciiCode) {
context.report({
loc: comment.loc,
messageId: "spaceWithEnZh",
});
}
}
}
},
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-jlc",
"version": "0.0.3",
"version": "0.0.4",
"description": "Preferences of eslint for jlc and jlc eda",
"keywords": [
"eslint",
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/comments-need-space.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ruleTester.run("comments-need-space", rule, {
valid: [
// give me some code that won't trigger a warning
"// give me some code that won't trigger a warning",
"// give me some code that won't trigger a warning 中英文混排,需要加空格",
],

invalid: [
Expand All @@ -31,5 +32,11 @@ ruleTester.run("comments-need-space", rule, {
}`,
errors: [{ messageId: "needSpace", type: null }],
},
{
code: `function hello() {
// give me some code that won't trigger a warning中英文混排,需要加空格
}`,
errors: [{ messageId: "spaceWithEnZh", type: null }],
},
],
});

0 comments on commit 716abf1

Please sign in to comment.