Skip to content

Commit 9be0de2

Browse files
committed
feedback
1 parent f303cb2 commit 9be0de2

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

rules/isolated-functions.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ const create = context => {
7171
}
7272
};
7373

74+
const isComment = token => token?.type === 'Block' || token?.type === 'Line';
75+
7476
/**
7577
Find a comment on this node or its parent, in cases where the node passed is part of a variable or export declaration.
7678
@param {import('estree').Node} node
@@ -79,7 +81,7 @@ const create = context => {
7981
let previousToken = sourceCode.getTokenBefore(node, {includeComments: true});
8082
let commentableNode = node;
8183
while (
82-
(previousToken?.type !== 'Block' && previousToken?.type !== 'Line')
84+
!isComment(previousToken)
8385
&& (commentableNode.parent.type === 'VariableDeclarator'
8486
|| commentableNode.parent.type === 'VariableDeclaration'
8587
|| commentableNode.parent.type === 'ExportNamedDeclaration'
@@ -89,7 +91,7 @@ const create = context => {
8991
previousToken = sourceCode.getTokenBefore(commentableNode, {includeComments: true});
9092
}
9193

92-
if (previousToken?.type === 'Block' || previousToken?.type === 'Line') {
94+
if (isComment(previousToken)) {
9395
return previousToken.value;
9496
}
9597
};
@@ -107,7 +109,7 @@ const create = context => {
107109
.replace(/(\*\s*)*/, '') // JSDoc comments like `/** @isolated */` are parsed into `* @isolated`. And `/**\n * @isolated */` is parsed into `*\n * @isolated`
108110
.trim()
109111
.toLowerCase();
110-
const match = options.comments.find(comment => previousComment === comment || previousComment.startsWith(`${comment} - `));
112+
const match = options.comments.find(comment => previousComment === comment || previousComment.startsWith(`${comment} - `) || previousComment.startsWith(`${comment} -- `));
111113
if (match) {
112114
return `follows comment ${JSON.stringify(match)}`;
113115
}

test/isolated-functions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ test({
9191
const foo = 'hi';
9292
// @isolated - explanation
9393
const abc1 = () => foo.slice();
94+
95+
// @isolated -- explanation
96+
const abc2 = () => foo.slice();
9497
`,
95-
errors: [error({name: 'foo', reason: 'follows comment "@isolated"'})],
98+
errors: [
99+
error({name: 'foo', reason: 'follows comment "@isolated"'}),
100+
error({name: 'foo', reason: 'follows comment "@isolated"'}),
101+
],
96102
},
97103
{
98104
name: '@isolated block comments',

0 commit comments

Comments
 (0)