UNPKG

746 BJavaScriptView Raw
1'use strict';
2const getDocumentationUrl = require('./utils/get-documentation-url');
3
4const MESSAGE_ID = 'noObjectAsDefaultParameter';
5
6const objectParameterSelector = [
7 ':function > AssignmentPattern.params',
8 '[left.type="Identifier"]',
9 '[right.type="ObjectExpression"]',
10 '[right.properties.length>0]'
11].join('');
12
13const create = context => {
14 return {
15 [objectParameterSelector]: node => {
16 context.report({
17 node: node.left,
18 messageId: MESSAGE_ID,
19 data: {parameter: node.left.name}
20 });
21 }
22 };
23};
24
25module.exports = {
26 create,
27 meta: {
28 type: 'problem',
29 docs: {
30 url: getDocumentationUrl(__filename)
31 },
32 messages: {
33 [MESSAGE_ID]: 'Do not use an object literal as default for parameter `{{parameter}}`.'
34 }
35 }
36};