Skip to content

Commit

Permalink
Style
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Dec 11, 2020
1 parent 43f60a1 commit 4896429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 10 additions & 9 deletions rules/prefer-date-now.js
Expand Up @@ -8,7 +8,7 @@ const MESSAGE_ID_NUMBER = 'prefer-date-now-over-number-data-object';
const messages = {
[MESSAGE_ID_DEFAULT]: 'Prefer `Date.now()` over `new Date()`.',
[MESSAGE_ID_METHOD]: 'Prefer `Date.now()` over `Date#{{method}}()`.',
[MESSAGE_ID_NUMBER]: 'Prefer `Date.now()` over `Number(new Date())`.',
[MESSAGE_ID_NUMBER]: 'Prefer `Date.now()` over `Number(new Date())`.'
};

const createNewDateSelector = path => {
Expand All @@ -20,6 +20,7 @@ const createNewDateSelector = path => {
`[${prefix}arguments.length=0]`
].join('');
};

const operatorsSelector = (...operators) => `:matches(${
operators.map(operator => `[operator="${operator}"]`).join(', ')
})`;
Expand All @@ -29,7 +30,7 @@ const methodsSelector = [
names: ['getTime', 'valueOf'],
length: 0
}),
createNewDateSelector('callee.object'),
createNewDateSelector('callee.object')
].join('');
const constructorsSelector = [
'CallExpression',
Expand Down Expand Up @@ -60,11 +61,11 @@ const binaryExpressionSelector = [

const create = context => {
const report = (node, problem) => context.report({
node,
messageId: MESSAGE_ID_DEFAULT,
fix: fixer => fixer.replaceText(node, 'Date.now()'),
...problem
})
node,
messageId: MESSAGE_ID_DEFAULT,
fix: fixer => fixer.replaceText(node, 'Date.now()'),
...problem
});

return {
[methodsSelector](node) {
Expand All @@ -79,7 +80,7 @@ const create = context => {
const {name} = node.callee;
if (name === 'Number') {
report(node, {
messageId: MESSAGE_ID_NUMBER,
messageId: MESSAGE_ID_NUMBER
});
} else {
report(node.arguments[0]);
Expand All @@ -94,7 +95,7 @@ const create = context => {
[binaryExpressionSelector](node) {
report(node);
}
}
};
};

const schema = [];
Expand Down
1 change: 0 additions & 1 deletion test/prefer-date-now.js
@@ -1,4 +1,3 @@
import {outdent} from 'outdent';
import {test} from './utils/test';

test({
Expand Down

0 comments on commit 4896429

Please sign in to comment.