440 lines
14 KiB
Diff
440 lines
14 KiB
Diff
diff --git a/.eslintrc b/.eslintrc
|
|
deleted file mode 100644
|
|
index d10247d2..00000000
|
|
--- a/.eslintrc
|
|
+++ /dev/null
|
|
@@ -1,82 +0,0 @@
|
|
-{
|
|
- "root": true,
|
|
- "extends": ["airbnb-base", "plugin:eslint-plugin/recommended"],
|
|
- "plugins": ["eslint-plugin"],
|
|
- "env": {
|
|
- "es6": true,
|
|
- "node": true
|
|
- },
|
|
- "parserOptions": {
|
|
- "ecmaVersion": 6,
|
|
- "ecmaFeatures": {
|
|
- "jsx": true
|
|
- },
|
|
- "sourceType": "script",
|
|
- },
|
|
- "ignorePatterns": [
|
|
- "coverage/",
|
|
- ".nyc_output/",
|
|
- ],
|
|
- "rules": {
|
|
- "comma-dangle": [2, "always-multiline"],
|
|
- "object-shorthand": [2, "always", {
|
|
- "ignoreConstructors": false,
|
|
- "avoidQuotes": false, // this is the override vs airbnb
|
|
- }],
|
|
- "max-len": [2, 120, {
|
|
- "ignoreStrings": true,
|
|
- "ignoreTemplateLiterals": true,
|
|
- "ignoreComments": true,
|
|
- }],
|
|
- "consistent-return": 0,
|
|
-
|
|
- "prefer-destructuring": [2, { "array": false, "object": false }, { "enforceForRenamedProperties": false }],
|
|
- "prefer-object-spread": 0, // until node 8 is required
|
|
- "prefer-rest-params": 0, // until node 6 is required
|
|
- "prefer-spread": 0, // until node 6 is required
|
|
- "function-call-argument-newline": 1, // TODO: enable
|
|
- "function-paren-newline": 0,
|
|
- "no-plusplus": [2, {"allowForLoopAfterthoughts": true}],
|
|
- "no-param-reassign": 1,
|
|
- "no-restricted-syntax": [2, {
|
|
- "selector": "ObjectPattern",
|
|
- "message": "Object destructuring is not compatible with Node v4"
|
|
- }],
|
|
- "strict": [2, "safe"],
|
|
- "valid-jsdoc": [2, {
|
|
- "requireReturn": false,
|
|
- "requireParamDescription": false,
|
|
- "requireReturnDescription": false,
|
|
- }],
|
|
-
|
|
- "eslint-plugin/consistent-output": 0,
|
|
- "eslint-plugin/require-meta-docs-description": [2, { "pattern": "^(Enforce|Require|Disallow)" }],
|
|
- "eslint-plugin/require-meta-schema": 0,
|
|
- "eslint-plugin/require-meta-type": 0
|
|
- },
|
|
- "overrides": [
|
|
- {
|
|
- "files": "tests/**",
|
|
- "rules": {
|
|
- "no-template-curly-in-string": 1,
|
|
- },
|
|
- },
|
|
- {
|
|
- "files": "markdown.config.js",
|
|
- "rules": {
|
|
- "no-console": 0,
|
|
- },
|
|
- },
|
|
- {
|
|
- "files": ".github/workflows/*.js",
|
|
- "parserOptions": {
|
|
- "ecmaVersion": 2019,
|
|
- },
|
|
- "rules": {
|
|
- "camelcase": 0,
|
|
- "no-console": 0,
|
|
- "no-restricted-syntax": 0,
|
|
- },
|
|
- },
|
|
- ],
|
|
- }
|
|
diff --git a/index.js b/index.js
|
|
index 4140c6c8..03e623af 100644
|
|
--- a/index.js
|
|
+++ b/index.js
|
|
@@ -1,31 +1,25 @@
|
|
-'use strict';
|
|
-
|
|
-const configAll = require('./configs/all');
|
|
-const configRecommended = require('./configs/recommended');
|
|
-const configRuntime = require('./configs/jsx-runtime');
|
|
-
|
|
-const allRules = require('./lib/rules');
|
|
+import configAll from './configs/all';
|
|
+import configRecommended from './configs/recommended';
|
|
+import configRuntime from './configs/jsx-runtime';
|
|
+import { name } from './package.json';
|
|
+export { default as rules } from './lib/rules';
|
|
|
|
// for legacy config system
|
|
-const plugins = [
|
|
- 'react',
|
|
-];
|
|
+const plugins = [name];
|
|
+
|
|
+export const deprecatedRules = configAll.plugins.react.deprecatedRules;
|
|
|
|
-module.exports = {
|
|
- deprecatedRules: configAll.plugins.react.deprecatedRules,
|
|
- rules: allRules,
|
|
- configs: {
|
|
- recommended: Object.assign({}, configRecommended, {
|
|
- parserOptions: configRecommended.languageOptions.parserOptions,
|
|
- plugins,
|
|
- }),
|
|
- all: Object.assign({}, configAll, {
|
|
- parserOptions: configAll.languageOptions.parserOptions,
|
|
- plugins,
|
|
- }),
|
|
- 'jsx-runtime': Object.assign({}, configRuntime, {
|
|
- parserOptions: configRuntime.languageOptions.parserOptions,
|
|
- plugins,
|
|
- }),
|
|
- },
|
|
+export const configs = {
|
|
+ recommended: Object.assign({}, configRecommended, {
|
|
+ parserOptions: configRecommended.languageOptions.parserOptions,
|
|
+ plugins,
|
|
+ }),
|
|
+ all: Object.assign({}, configAll, {
|
|
+ parserOptions: configAll.languageOptions.parserOptions,
|
|
+ plugins,
|
|
+ }),
|
|
+ 'jsx-runtime': Object.assign({}, configRuntime, {
|
|
+ parserOptions: configRuntime.languageOptions.parserOptions,
|
|
+ plugins,
|
|
+ }),
|
|
};
|
|
diff --git a/lib/rules/button-has-type.js b/lib/rules/button-has-type.js
|
|
index d4059606..982dd343 100644
|
|
--- a/lib/rules/button-has-type.js
|
|
+++ b/lib/rules/button-has-type.js
|
|
@@ -5,8 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const getProp = require('jsx-ast-utils/getProp');
|
|
-const getLiteralPropValue = require('jsx-ast-utils/getLiteralPropValue');
|
|
+const { getProp, getLiteralPropValue } = require('jsx-ast-utils');
|
|
const docsUrl = require('../util/docsUrl');
|
|
const isCreateElement = require('../util/isCreateElement');
|
|
const report = require('../util/report');
|
|
diff --git a/lib/rules/jsx-fragments.js b/lib/rules/jsx-fragments.js
|
|
index 4dadb076..de01ae32 100644
|
|
--- a/lib/rules/jsx-fragments.js
|
|
+++ b/lib/rules/jsx-fragments.js
|
|
@@ -5,7 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const elementType = require('jsx-ast-utils/elementType');
|
|
+import { elementType } from 'jsx-ast-utils';
|
|
const pragmaUtil = require('../util/pragma');
|
|
const variableUtil = require('../util/variable');
|
|
const testReactVersion = require('../util/version').testReactVersion;
|
|
diff --git a/lib/rules/jsx-key.js b/lib/rules/jsx-key.js
|
|
index 825d21f4..fb4459dd 100644
|
|
--- a/lib/rules/jsx-key.js
|
|
+++ b/lib/rules/jsx-key.js
|
|
@@ -5,8 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const hasProp = require('jsx-ast-utils/hasProp');
|
|
-const propName = require('jsx-ast-utils/propName');
|
|
+import { hasProp, propName } from 'jsx-ast-utils';
|
|
const values = require('object.values');
|
|
const docsUrl = require('../util/docsUrl');
|
|
const pragmaUtil = require('../util/pragma');
|
|
diff --git a/lib/rules/jsx-no-bind.js b/lib/rules/jsx-no-bind.js
|
|
index 4d6e349d..6cc8fbc3 100644
|
|
--- a/lib/rules/jsx-no-bind.js
|
|
+++ b/lib/rules/jsx-no-bind.js
|
|
@@ -7,7 +7,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const propName = require('jsx-ast-utils/propName');
|
|
+import { propName } from 'jsx-ast-utils';
|
|
const docsUrl = require('../util/docsUrl');
|
|
const jsxUtil = require('../util/jsx');
|
|
const report = require('../util/report');
|
|
diff --git a/lib/rules/jsx-pascal-case.js b/lib/rules/jsx-pascal-case.js
|
|
index efeef403..33df4653 100644
|
|
--- a/lib/rules/jsx-pascal-case.js
|
|
+++ b/lib/rules/jsx-pascal-case.js
|
|
@@ -5,7 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const elementType = require('jsx-ast-utils/elementType');
|
|
+import { elementType } from 'jsx-ast-utils';
|
|
const minimatch = require('minimatch');
|
|
const docsUrl = require('../util/docsUrl');
|
|
const jsxUtil = require('../util/jsx');
|
|
diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js
|
|
index f811e16c..ebbde786 100644
|
|
--- a/lib/rules/jsx-sort-props.js
|
|
+++ b/lib/rules/jsx-sort-props.js
|
|
@@ -5,7 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const propName = require('jsx-ast-utils/propName');
|
|
+import { propName } from 'jsx-ast-utils';
|
|
const includes = require('array-includes');
|
|
const toSorted = require('array.prototype.tosorted');
|
|
|
|
diff --git a/lib/rules/no-namespace.js b/lib/rules/no-namespace.js
|
|
index 20ca5d93..22eb516f 100644
|
|
--- a/lib/rules/no-namespace.js
|
|
+++ b/lib/rules/no-namespace.js
|
|
@@ -5,7 +5,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const elementType = require('jsx-ast-utils/elementType');
|
|
+import { elementType } from 'jsx-ast-utils';
|
|
const docsUrl = require('../util/docsUrl');
|
|
const isCreateElement = require('../util/isCreateElement');
|
|
const report = require('../util/report');
|
|
diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js
|
|
index 3e8c6de1..0b3224a3 100644
|
|
--- a/lib/rules/no-unknown-property.js
|
|
+++ b/lib/rules/no-unknown-property.js
|
|
@@ -544,7 +544,7 @@ module.exports = {
|
|
|
|
create(context) {
|
|
function getIgnoreConfig() {
|
|
- return (context.options[0] && context.options[0].ignore) || DEFAULTS.ignore;
|
|
+ return context.options[0]?.ignore || DEFAULTS.ignore;
|
|
}
|
|
|
|
function getRequireDataLowercase() {
|
|
diff --git a/lib/util/annotations.js b/lib/util/annotations.js
|
|
index 24b18074..cc7e6faa 100644
|
|
--- a/lib/util/annotations.js
|
|
+++ b/lib/util/annotations.js
|
|
@@ -29,6 +29,6 @@ function isAnnotatedFunctionPropsDeclaration(node, context) {
|
|
return (isAnnotated && (isDestructuredProps || isProps));
|
|
}
|
|
|
|
-module.exports = {
|
|
+export {
|
|
isAnnotatedFunctionPropsDeclaration,
|
|
};
|
|
diff --git a/lib/util/ast.js b/lib/util/ast.js
|
|
index 5664dcb5..82f81709 100644
|
|
--- a/lib/util/ast.js
|
|
+++ b/lib/util/ast.js
|
|
@@ -4,12 +4,8 @@
|
|
|
|
'use strict';
|
|
|
|
-const estraverse = require('estraverse');
|
|
-const eslintUtil = require('./eslint');
|
|
-
|
|
-const getFirstTokens = eslintUtil.getFirstTokens;
|
|
-const getScope = eslintUtil.getScope;
|
|
-const getSourceCode = eslintUtil.getSourceCode;
|
|
+import estraverse from 'estraverse';
|
|
+import { getFirstTokens, getScope, getSourceCode } from './eslint.js';
|
|
// const pragmaUtil = require('./pragma');
|
|
|
|
/**
|
|
@@ -19,11 +15,15 @@ const getSourceCode = eslintUtil.getSourceCode;
|
|
* @param {Object} visitor Visitor Object for estraverse
|
|
*/
|
|
function traverse(ASTnode, visitor) {
|
|
- const opts = Object.assign({}, {
|
|
- fallback(node) {
|
|
- return Object.keys(node).filter((key) => key === 'children' || key === 'argument');
|
|
+ const opts = Object.assign(
|
|
+ {},
|
|
+ {
|
|
+ fallback(node) {
|
|
+ return Object.keys(node).filter(key => key === 'children' || key === 'argument');
|
|
+ },
|
|
},
|
|
- }, visitor);
|
|
+ visitor,
|
|
+ );
|
|
|
|
opts.keys = Object.assign({}, visitor.keys, {
|
|
JSXElement: ['children'],
|
|
@@ -56,8 +56,8 @@ function loopNodes(nodes) {
|
|
*/
|
|
function findReturnStatement(node) {
|
|
if (
|
|
- (!node.value || !node.value.body || !node.value.body.body)
|
|
- && (!node.body || !node.body.body)
|
|
+ (!node.value || !node.value.body || !node.value.body.body) &&
|
|
+ (!node.body || !node.body.body)
|
|
) {
|
|
return false;
|
|
}
|
|
@@ -110,10 +110,10 @@ function traverseReturns(ASTNode, context, onReturn) {
|
|
*/
|
|
|
|
if (
|
|
- nodeType !== 'FunctionExpression'
|
|
- && nodeType !== 'FunctionDeclaration'
|
|
- && nodeType !== 'ArrowFunctionExpression'
|
|
- && nodeType !== 'MethodDefinition'
|
|
+ nodeType !== 'FunctionExpression' &&
|
|
+ nodeType !== 'FunctionDeclaration' &&
|
|
+ nodeType !== 'ArrowFunctionExpression' &&
|
|
+ nodeType !== 'MethodDefinition'
|
|
) {
|
|
return;
|
|
}
|
|
@@ -196,13 +196,8 @@ function getFirstNodeInLine(context, node) {
|
|
let lines;
|
|
do {
|
|
token = sourceCode.getTokenBefore(token);
|
|
- lines = token.type === 'JSXText'
|
|
- ? token.value.split('\n')
|
|
- : null;
|
|
- } while (
|
|
- token.type === 'JSXText'
|
|
- && /^\s*$/.test(lines[lines.length - 1])
|
|
- );
|
|
+ lines = token.type === 'JSXText' ? token.value.split('\n') : null;
|
|
+ } while (token.type === 'JSXText' && /^\s*$/.test(lines[lines.length - 1]));
|
|
return token;
|
|
}
|
|
|
|
@@ -291,10 +286,9 @@ function stripQuotes(string) {
|
|
function getKeyValue(context, node) {
|
|
if (node.type === 'ObjectTypeProperty') {
|
|
const tokens = getFirstTokens(context, node, 2);
|
|
- return (tokens[0].value === '+' || tokens[0].value === '-'
|
|
+ return tokens[0].value === '+' || tokens[0].value === '-'
|
|
? tokens[1].value
|
|
- : stripQuotes(tokens[0].value)
|
|
- );
|
|
+ : stripQuotes(tokens[0].value);
|
|
}
|
|
if (node.type === 'GenericTypeAnnotation') {
|
|
return node.id.name;
|
|
@@ -321,9 +315,14 @@ function isParenthesized(context, node) {
|
|
const previousToken = sourceCode.getTokenBefore(node);
|
|
const nextToken = sourceCode.getTokenAfter(node);
|
|
|
|
- return !!previousToken && !!nextToken
|
|
- && previousToken.value === '(' && previousToken.range[1] <= node.range[0]
|
|
- && nextToken.value === ')' && nextToken.range[0] >= node.range[1];
|
|
+ return (
|
|
+ !!previousToken &&
|
|
+ !!nextToken &&
|
|
+ previousToken.value === '(' &&
|
|
+ previousToken.range[1] <= node.range[0] &&
|
|
+ nextToken.value === ')' &&
|
|
+ nextToken.range[0] >= node.range[1]
|
|
+ );
|
|
}
|
|
|
|
/**
|
|
@@ -333,9 +332,9 @@ function isParenthesized(context, node) {
|
|
*/
|
|
function isAssignmentLHS(node) {
|
|
return (
|
|
- node.parent
|
|
- && node.parent.type === 'AssignmentExpression'
|
|
- && node.parent.left === node
|
|
+ node.parent &&
|
|
+ node.parent.type === 'AssignmentExpression' &&
|
|
+ node.parent.left === node
|
|
);
|
|
}
|
|
|
|
@@ -434,7 +433,7 @@ function isTSTypeParameterInstantiation(node) {
|
|
return nodeType === 'TSTypeParameterInstantiation';
|
|
}
|
|
|
|
-module.exports = {
|
|
+export {
|
|
traverse,
|
|
findReturnStatement,
|
|
getFirstNodeInLine,
|
|
diff --git a/lib/util/jsx.js b/lib/util/jsx.js
|
|
index 07a09a80..0b9b139f 100644
|
|
--- a/lib/util/jsx.js
|
|
+++ b/lib/util/jsx.js
|
|
@@ -4,7 +4,7 @@
|
|
|
|
'use strict';
|
|
|
|
-const elementType = require('jsx-ast-utils/elementType');
|
|
+import { elementType } from 'jsx-ast-utils';
|
|
|
|
const astUtil = require('./ast');
|
|
const isCreateElement = require('./isCreateElement');
|
|
diff --git a/tsconfig.json b/tsconfig.json
|
|
deleted file mode 100644
|
|
index 39187b7f..00000000
|
|
--- a/tsconfig.json
|
|
+++ /dev/null
|
|
@@ -1,23 +0,0 @@
|
|
-{
|
|
- "compilerOptions": {
|
|
- "target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
|
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
|
- // "lib": ["es2015"], /* Specify library files to be included in the compilation. */
|
|
- "allowJs": true, /* Allow javascript files to be compiled. */
|
|
- "checkJs": true, /* Report errors in .js files. */
|
|
- "noEmit": true, /* Do not emit outputs. */
|
|
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
-
|
|
- /* Strict Type-Checking Options */
|
|
- // "strict": true, /* Enable all strict type-checking options. */
|
|
- "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
- // "strictNullChecks": true, /* Enable strict null checks. */
|
|
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
- "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
- "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
- "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
- "alwaysStrict": false, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
- "resolveJsonModule": true
|
|
- },
|
|
- "include": ["lib"],
|
|
-}
|