Update
This commit is contained in:
parent
60b1b8fde3
commit
a022050ab4
2
dist/index.d.ts
vendored
2
dist/index.d.ts
vendored
@ -20,6 +20,8 @@ export interface LocalRuleOptions {
|
|||||||
"rules/restrict-template-expressions": RuleEntry<{
|
"rules/restrict-template-expressions": RuleEntry<{
|
||||||
allow: string[];
|
allow: string[];
|
||||||
}>;
|
}>;
|
||||||
|
/** Ban assignment of empty object literals `{}` and replace them with `Object.create(null)` */
|
||||||
|
"rules/no-empty-object-literal": RuleEntry<unknown>;
|
||||||
}
|
}
|
||||||
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
||||||
/**
|
/**
|
||||||
|
8
dist/package.json
vendored
8
dist/package.json
vendored
@ -9,10 +9,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@eslint-community/eslint-utils": "^4.4.0",
|
"@eslint-community/eslint-utils": "^4.4.0",
|
||||||
"@types/eslint": "^8.44.7",
|
"@types/eslint": "^8.44.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
||||||
"@typescript-eslint/parser": "^6.10.0",
|
"@typescript-eslint/parser": "^6.11.0",
|
||||||
"@typescript-eslint/type-utils": "^6.10.0",
|
"@typescript-eslint/type-utils": "^6.11.0",
|
||||||
"@typescript-eslint/utils": "^6.10.0",
|
"@typescript-eslint/utils": "^6.11.0",
|
||||||
"aria-query": "^5.3.0",
|
"aria-query": "^5.3.0",
|
||||||
"axe-core": "4.8.2",
|
"axe-core": "4.8.2",
|
||||||
"axobject-query": "^4.0.0",
|
"axobject-query": "^4.0.0",
|
||||||
|
18
package.json
18
package.json
@ -6,9 +6,9 @@
|
|||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.23.2",
|
"@babel/core": "^7.23.3",
|
||||||
"@babel/plugin-transform-flow-strip-types": "^7.22.5",
|
"@babel/plugin-transform-flow-strip-types": "^7.23.3",
|
||||||
"@babel/preset-env": "^7.23.2",
|
"@babel/preset-env": "^7.23.3",
|
||||||
"@types/babel-plugin-macros": "^3.1.3",
|
"@types/babel-plugin-macros": "^3.1.3",
|
||||||
"@types/babel__core": "^7.20.4",
|
"@types/babel__core": "^7.20.4",
|
||||||
"@types/eslint": "^8.44.7",
|
"@types/eslint": "^8.44.7",
|
||||||
@ -16,11 +16,11 @@
|
|||||||
"@types/estree-jsx": "^1.0.3",
|
"@types/estree-jsx": "^1.0.3",
|
||||||
"@types/lodash": "^4.14.201",
|
"@types/lodash": "^4.14.201",
|
||||||
"@types/node": "^20.9.0",
|
"@types/node": "^20.9.0",
|
||||||
"@typescript-eslint/eslint-plugin": "6.10.0",
|
"@typescript-eslint/eslint-plugin": "6.11.0",
|
||||||
"@typescript-eslint/type-utils": "^6.10.0",
|
"@typescript-eslint/type-utils": "^6.11.0",
|
||||||
"@typescript-eslint/types": "^6.10.0",
|
"@typescript-eslint/types": "^6.11.0",
|
||||||
"@typescript-eslint/typescript-estree": "^6.10.0",
|
"@typescript-eslint/typescript-estree": "^6.11.0",
|
||||||
"@typescript-eslint/utils": "^6.10.0",
|
"@typescript-eslint/utils": "^6.11.0",
|
||||||
"babel-plugin-macros": "^3.1.0",
|
"babel-plugin-macros": "^3.1.0",
|
||||||
"dts-bundle-generator": "^8.1.2",
|
"dts-bundle-generator": "^8.1.2",
|
||||||
"esbin": "0.0.4",
|
"esbin": "0.0.4",
|
||||||
@ -34,7 +34,7 @@
|
|||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"minimatch": "^9.0.3",
|
"minimatch": "^9.0.3",
|
||||||
"picocolors": "^1.0.0",
|
"picocolors": "^1.0.0",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.1.0",
|
||||||
"prop-types": "^15.8.1",
|
"prop-types": "^15.8.1",
|
||||||
"typescript": "5.2.2"
|
"typescript": "5.2.2"
|
||||||
},
|
},
|
||||||
|
@ -237,10 +237,10 @@ index 64bbc8d5..b5e9c803 100644
|
|||||||
const isCreateElement = require('../util/isCreateElement');
|
const isCreateElement = require('../util/isCreateElement');
|
||||||
const report = require('../util/report');
|
const report = require('../util/report');
|
||||||
diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js
|
diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js
|
||||||
index 069596d7..c155e777 100644
|
index 2fc127b1..64d093b8 100644
|
||||||
--- a/lib/rules/no-unknown-property.js
|
--- a/lib/rules/no-unknown-property.js
|
||||||
+++ b/lib/rules/no-unknown-property.js
|
+++ b/lib/rules/no-unknown-property.js
|
||||||
@@ -539,7 +539,7 @@ module.exports = {
|
@@ -540,7 +540,7 @@ module.exports = {
|
||||||
|
|
||||||
create(context) {
|
create(context) {
|
||||||
function getIgnoreConfig() {
|
function getIgnoreConfig() {
|
||||||
@ -249,7 +249,7 @@ index 069596d7..c155e777 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getRequireDataLowercase() {
|
function getRequireDataLowercase() {
|
||||||
@@ -552,7 +552,7 @@ module.exports = {
|
@@ -553,7 +553,7 @@ module.exports = {
|
||||||
JSXAttribute(node) {
|
JSXAttribute(node) {
|
||||||
const ignoreNames = getIgnoreConfig();
|
const ignoreNames = getIgnoreConfig();
|
||||||
const actualName = context.getSourceCode().getText(node.name);
|
const actualName = context.getSourceCode().getText(node.name);
|
||||||
@ -258,7 +258,7 @@ index 069596d7..c155e777 100644
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const name = normalizeAttributeCase(actualName);
|
const name = normalizeAttributeCase(actualName);
|
||||||
@@ -580,6 +580,15 @@ module.exports = {
|
@@ -581,6 +581,15 @@ module.exports = {
|
||||||
|
|
||||||
const tagName = getTagName(node);
|
const tagName = getTagName(node);
|
||||||
|
|
||||||
|
849
pnpm-lock.yaml
generated
849
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -32,6 +32,8 @@ export interface LocalRuleOptions {
|
|||||||
* @see [restrict-template-expressions](https://typescript-eslint.io/rules/restrict-template-expressions)
|
* @see [restrict-template-expressions](https://typescript-eslint.io/rules/restrict-template-expressions)
|
||||||
*/
|
*/
|
||||||
'rules/restrict-template-expressions': RuleEntry<{ allow: string[] }>;
|
'rules/restrict-template-expressions': RuleEntry<{ allow: string[] }>;
|
||||||
|
/** Ban assignment of empty object literals `{}` and replace them with `Object.create(null)` */
|
||||||
|
'rules/no-empty-object-literal': RuleEntry<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
export type RuleOptions = Rules & Partial<LocalRuleOptions>;
|
||||||
|
@ -27,10 +27,7 @@ export const typescriptRules: Partial<TypeScriptRules> = {
|
|||||||
'@typescript-eslint/no-unsafe-call': off,
|
'@typescript-eslint/no-unsafe-call': off,
|
||||||
'@typescript-eslint/no-unsafe-member-access': off,
|
'@typescript-eslint/no-unsafe-member-access': off,
|
||||||
'@typescript-eslint/no-unsafe-return': off,
|
'@typescript-eslint/no-unsafe-return': off,
|
||||||
'@typescript-eslint/no-unused-vars': [
|
'@typescript-eslint/no-unused-vars': off,
|
||||||
error,
|
|
||||||
{ ignoreRestSiblings: true, varsIgnorePattern: '^_' },
|
|
||||||
],
|
|
||||||
'@typescript-eslint/no-use-before-define': off,
|
'@typescript-eslint/no-use-before-define': off,
|
||||||
'@typescript-eslint/no-var-requires': off,
|
'@typescript-eslint/no-var-requires': off,
|
||||||
'@typescript-eslint/restrict-template-expressions': off,
|
'@typescript-eslint/restrict-template-expressions': off,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import type { Rule } from 'eslint';
|
import type { Rule } from 'eslint';
|
||||||
import type { ESLintUtils } from '@typescript-eslint/utils';
|
import type { ESLintUtils } from '@typescript-eslint/utils';
|
||||||
|
|
||||||
|
import noEmptyObjectLiteral from './no-empty-object-literal';
|
||||||
import noImportDot from './no-import-dot';
|
import noImportDot from './no-import-dot';
|
||||||
import restrictTemplateExpressions from './restrict-template-expressions';
|
import restrictTemplateExpressions from './restrict-template-expressions';
|
||||||
|
|
||||||
@ -8,6 +9,7 @@ export const rules: Record<
|
|||||||
string,
|
string,
|
||||||
Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>
|
Rule.RuleModule | ESLintUtils.RuleModule<string, unknown[]>
|
||||||
> = {
|
> = {
|
||||||
|
'no-empty-object-literal': noEmptyObjectLiteral,
|
||||||
'no-import-dot': noImportDot,
|
'no-import-dot': noImportDot,
|
||||||
'restrict-template-expressions': restrictTemplateExpressions,
|
'restrict-template-expressions': restrictTemplateExpressions,
|
||||||
};
|
};
|
||||||
|
32
src/rules/no-empty-object-literal.ts
Normal file
32
src/rules/no-empty-object-literal.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import type { Rule } from 'eslint';
|
||||||
|
|
||||||
|
const rule: Rule.RuleModule = {
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description:
|
||||||
|
'Ban assignment of empty object literals `{}` and replace them with `Object.create(null)`',
|
||||||
|
category: 'Best Practices',
|
||||||
|
recommended: true,
|
||||||
|
},
|
||||||
|
fixable: 'code',
|
||||||
|
},
|
||||||
|
create: context => ({
|
||||||
|
AssignmentExpression(node) {
|
||||||
|
if (
|
||||||
|
node.operator === '=' &&
|
||||||
|
node.right.type === 'ObjectExpression' &&
|
||||||
|
node.right.properties.length === 0
|
||||||
|
) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
message:
|
||||||
|
'Assigning empty object literals are not allowed, use `Object.create(null)` instead.',
|
||||||
|
fix: fixer => fixer.replaceText(node.right, 'Object.create(null)'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
export default rule;
|
Loading…
x
Reference in New Issue
Block a user