Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
656f91ae61 | ||
|
cdb02c8fa1 | ||
|
3f2f335e42 | ||
|
3ca0e7ea8b | ||
|
96dd9a1797 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-monorepo",
|
"name": "@antfu/eslint-config-monorepo",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@8.3.0",
|
"packageManager": "pnpm@8.3.0",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
|
@@ -59,7 +59,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
files: ['*.json', '*.json5'],
|
files: ['*.json', '*.json5', '*.jsonc'],
|
||||||
parser: 'jsonc-eslint-parser',
|
parser: 'jsonc-eslint-parser',
|
||||||
rules: {
|
rules: {
|
||||||
'jsonc/array-bracket-spacing': ['error', 'never'],
|
'jsonc/array-bracket-spacing': ['error', 'never'],
|
||||||
@@ -202,6 +202,8 @@ module.exports = {
|
|||||||
'no-undef': 'off',
|
'no-undef': 'off',
|
||||||
'no-unused-expressions': 'off',
|
'no-unused-expressions': 'off',
|
||||||
'no-unused-vars': 'off',
|
'no-unused-vars': 'off',
|
||||||
|
'antfu/no-cjs-exports': 'off',
|
||||||
|
'antfu/no-ts-export-equal': 'off',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-basic",
|
"name": "@antfu/eslint-config-basic",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-react",
|
"name": "@antfu/eslint-config-react",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -158,6 +158,8 @@ module.exports = {
|
|||||||
|
|
||||||
// antfu
|
// antfu
|
||||||
'antfu/generic-spacing': 'error',
|
'antfu/generic-spacing': 'error',
|
||||||
|
'antfu/no-cjs-exports': 'error',
|
||||||
|
'antfu/no-ts-export-equal': 'error',
|
||||||
|
|
||||||
// off
|
// off
|
||||||
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
'@typescript-eslint/consistent-indexed-object-style': 'off',
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-ts",
|
"name": "@antfu/eslint-config-ts",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config-vue",
|
"name": "@antfu/eslint-config-vue",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@antfu/eslint-config",
|
"name": "@antfu/eslint-config",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"description": "Anthony's ESLint config",
|
"description": "Anthony's ESLint config",
|
||||||
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
"author": "Anthony Fu <anthonyfu117@hotmail.com> (https://github.com/antfu/)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "eslint-plugin-antfu",
|
"name": "eslint-plugin-antfu",
|
||||||
"version": "0.38.6",
|
"version": "0.39.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://github.com/antfu/eslint-config",
|
"homepage": "https://github.com/antfu/eslint-config",
|
||||||
"main": "./dist/index.cjs",
|
"main": "./dist/index.cjs",
|
||||||
|
@@ -3,6 +3,8 @@ import ifNewline from './rules/if-newline'
|
|||||||
import importDedupe from './rules/import-dedupe'
|
import importDedupe from './rules/import-dedupe'
|
||||||
import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
import preferInlineTypeImport from './rules/prefer-inline-type-import'
|
||||||
import topLevelFunction from './rules/top-level-function'
|
import topLevelFunction from './rules/top-level-function'
|
||||||
|
import noTsExportEqual from './rules/no-ts-export-equal'
|
||||||
|
import noCjsExports from './rules/no-cjs-exports'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
rules: {
|
rules: {
|
||||||
@@ -11,5 +13,7 @@ export default {
|
|||||||
'prefer-inline-type-import': preferInlineTypeImport,
|
'prefer-inline-type-import': preferInlineTypeImport,
|
||||||
'generic-spacing': genericSpacing,
|
'generic-spacing': genericSpacing,
|
||||||
'top-level-function': topLevelFunction,
|
'top-level-function': topLevelFunction,
|
||||||
|
'no-cjs-exports': noCjsExports,
|
||||||
|
'no-ts-export-equal': noTsExportEqual,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './no-cjs-exports'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
{ code: 'export = {}', filename: 'test.ts' },
|
||||||
|
{ code: 'exports.a = {}', filename: 'test.js' },
|
||||||
|
{ code: 'module.exports.a = {}', filename: 'test.js' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const invalids = [
|
||||||
|
{ code: 'exports.a = {}', filename: 'test.ts' },
|
||||||
|
{ code: 'module.exports.a = {}', filename: 'test.ts' },
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
...i,
|
||||||
|
errors: [{ messageId: 'noCjsExports' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
41
packages/eslint-plugin-antfu/src/rules/no-cjs-exports.ts
Normal file
41
packages/eslint-plugin-antfu/src/rules/no-cjs-exports.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'no-cjs-exports'
|
||||||
|
export type MessageIds = 'noCjsExports'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description: 'Do not use CJS exports',
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
noCjsExports: 'Use ESM export instead',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
const extension = context.getFilename().split('.').pop()
|
||||||
|
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
'MemberExpression[object.name="exports"]': function (node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noCjsExports',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
'MemberExpression[object.name="module"][property.name="exports"]': function (node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noCjsExports',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
@@ -0,0 +1,26 @@
|
|||||||
|
import { RuleTester } from '@typescript-eslint/utils/dist/ts-eslint'
|
||||||
|
import { it } from 'vitest'
|
||||||
|
import rule, { RULE_NAME } from './no-ts-export-equal'
|
||||||
|
|
||||||
|
const valids = [
|
||||||
|
{ code: 'export default {}', filename: 'test.ts' },
|
||||||
|
{ code: 'export = {}', filename: 'test.js' },
|
||||||
|
]
|
||||||
|
|
||||||
|
const invalids = [
|
||||||
|
{ code: 'export = {}', filename: 'test.ts' },
|
||||||
|
]
|
||||||
|
|
||||||
|
it('runs', () => {
|
||||||
|
const ruleTester: RuleTester = new RuleTester({
|
||||||
|
parser: require.resolve('@typescript-eslint/parser'),
|
||||||
|
})
|
||||||
|
|
||||||
|
ruleTester.run(RULE_NAME, rule, {
|
||||||
|
valid: valids,
|
||||||
|
invalid: invalids.map(i => ({
|
||||||
|
...i,
|
||||||
|
errors: [{ messageId: 'noTsExportEqual' }],
|
||||||
|
})),
|
||||||
|
})
|
||||||
|
})
|
35
packages/eslint-plugin-antfu/src/rules/no-ts-export-equal.ts
Normal file
35
packages/eslint-plugin-antfu/src/rules/no-ts-export-equal.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import { createEslintRule } from '../utils'
|
||||||
|
|
||||||
|
export const RULE_NAME = 'no-ts-export-equal'
|
||||||
|
export type MessageIds = 'noTsExportEqual'
|
||||||
|
export type Options = []
|
||||||
|
|
||||||
|
export default createEslintRule<Options, MessageIds>({
|
||||||
|
name: RULE_NAME,
|
||||||
|
meta: {
|
||||||
|
type: 'problem',
|
||||||
|
docs: {
|
||||||
|
description: 'Do not use `exports =`',
|
||||||
|
recommended: false,
|
||||||
|
},
|
||||||
|
schema: [],
|
||||||
|
messages: {
|
||||||
|
noTsExportEqual: 'Use ESM `export default` instead',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultOptions: [],
|
||||||
|
create: (context) => {
|
||||||
|
const extension = context.getFilename().split('.').pop()
|
||||||
|
if (!['ts', 'tsx', 'mts', 'cts'].includes(extension))
|
||||||
|
return {}
|
||||||
|
|
||||||
|
return {
|
||||||
|
TSExportAssignment(node) {
|
||||||
|
context.report({
|
||||||
|
node,
|
||||||
|
messageId: 'noTsExportEqual',
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
Reference in New Issue
Block a user