123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- module.exports = {
- rules: {
- 'no-spaces-in-conditionals': {
- meta: {
- docs: {
- description: 'Disallow spaces in conditionals',
- category: 'Z8 Stylistic Issues',
- recommended: true,
- },
- fixable: 'code',
- schema: [],
- },
- create: function (context) {
- return {
- IfStatement: function (node) {
- const tokens = context.getSourceCode().getTokens(node);
- const firstToken = tokens[0];
- const secondToken = tokens[1];
- if (
- firstToken.type === 'Keyword' &&
- firstToken.value === 'if' &&
- secondToken.type === 'Punctuator' &&
- secondToken.value === '(' &&
- secondToken.range[0] - firstToken.range[1] > 0
- ) {
- context.report({
- node: node,
- message: 'Do not use spaces between \'if\' and its condition',
- });
- }
- },
- };
- },
- },
- 'no-strict-equality': {
- meta: {
- docs: {
- description: 'Disallow strict equality operator',
- category: 'Z8 Stylistic Issues',
- recommended: true,
- },
- fixable: 'code',
- schema: [],
- },
- create: function (context) {
- return {
- BinaryExpression: function (node) {
- if (node.operator === '===') {
- context.report({
- node: node,
- message: 'Avoid using strict equality operator \'===\' (use loose equality operator \'==\' instead)',
- });
- }
- },
- };
- },
- },
- 'no-double-quotes': {
- meta: {
- docs: {
- description: 'Disallow double quotes',
- category: 'Z8 Stylistic Issues',
- recommended: true,
- },
- fixable: 'code',
- schema: [],
- },
- create: function (context) {
- return {
- Literal: function (node) {
- if (typeof node.value === 'string' && node.raw.includes('"')) {
- context.report({
- node: node,
- message: 'Avoid using double quotes (use single quotes instead)',
- });
- }
- },
- };
- },
- },
- 'no-arrow-functions': {
- meta: {
- docs: {
- description: 'Disallow arrow functions',
- category: 'Z8 Stylistic Issues',
- recommended: true,
- },
- fixable: 'code',
- schema: [],
- },
- create: function (context) {
- return {
- ArrowFunctionExpression: function (node) {
- context.report({
- node: node,
- message: 'Avoid using arrow functions',
- });
- },
- };
- },
- },
- 'no-function-declaration': {
- meta: {
- docs: {
- description: 'Disallow function declaration',
- category: 'Z8 Stylistic Issues',
- recommended: true,
- },
- fixable: 'code',
- schema: [],
- },
- create: function (context) {
- return {
- FunctionDeclaration: function (node) {
- context.report({
- node: node,
- message: 'Use function expression instead of function declaration',
- });
- },
- VariableDeclarator: function (node) {
- if (
- node.init &&
- node.init.type === 'FunctionExpression' &&
- node.init.id &&
- node.init.id.type === 'Identifier' &&
- node.id &&
- node.id.type === 'Identifier' &&
- node.init.id.name === node.id.name
- ) {
- context.report({
- node: node,
- message: 'Use function expression instead of function declaration',
- });
- }
- },
- };
- },
- },
- },
- };
|