Skip to content

Commit

Permalink
test(eslint-config-ali): fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyunhe committed Jan 2, 2025
1 parent 0e0d1ba commit d482c04
Show file tree
Hide file tree
Showing 35 changed files with 111 additions and 228 deletions.
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { base } from 'eslint-config-ali';

export default [...base, { ignores: ['fixtures'] }];
export default [...base, { ignores: ['**/bad/'] }];
2 changes: 1 addition & 1 deletion packages/eslint-config-ali/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- **破坏性变更**: 移除了 `eslint` 8.x 支持,仅支持 `eslint` 9.x
- **破坏性变更**: 产物改为 ESM,移除了原有文件导出,只导出单一默认对象
- **破坏性变更**: 移除 `rax`, `jsx-a11y`, `es5`, `node`, `egg` 配置
- **破坏性变更**: 移除 `rax`, `jsx-a11y`, `es5`, `node`, `egg`, `vue` 配置
- 支持 `.gitignore` (仅限项目根目录),不再需要 `.eslintignore` 文件
- 引入 `@stylistic/eslint-plugin` 统一 JS/TS/JSX 代码风格类规则

Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-ali/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { base } from './dist';

export default [...base, { ignores: ['fixtures'] }];
export default [...base, { ignores: ['bad/'] }];
4 changes: 2 additions & 2 deletions packages/eslint-config-ali/src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ts from 'typescript-eslint';
const typescript = ts.config({
name: 'ali/typescripts',
files: ['**/*.{cts,mts,ts,tsx,vue}'],
extends: [ts.configs.recommended],
extends: [ts.configs.recommendedTypeChecked],
languageOptions: {
parserOptions: {
project: true,
Expand Down Expand Up @@ -103,7 +103,7 @@ const typescript = ts.config({
* @extend
*/
'dot-notation': 'off',
'@typescript-eslint/dot-notation': ['error', { allowKeywords: true }],
'@typescript-eslint/dot-notation': 'error',

/**
* 【关闭】函数返回值必须与声明的类型一致
Expand Down
94 changes: 0 additions & 94 deletions packages/eslint-config-ali/src/configs/vue.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/eslint-config-ali/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export { default as base } from './presets/base';
export { default as react } from './presets/react';
export { default as vue } from './presets/vue';
2 changes: 0 additions & 2 deletions packages/eslint-config-ali/src/presets/react.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import react from '../configs/react';
import defineConfigArray from '../utils/defineConfigArray';
import base from './base';
Expand All @@ -8,6 +7,5 @@ export default defineConfigArray([
...base,
reactPlugin.configs.flat.recommended,
reactPlugin.configs.flat['jsx-runtime'],
reactHooksPlugin.configs.recommended,
react,
]);
6 changes: 0 additions & 6 deletions packages/eslint-config-ali/src/presets/vue.ts

This file was deleted.

36 changes: 0 additions & 36 deletions packages/eslint-config-ali/test/fixtures/ts-vue.vue

This file was deleted.

16 changes: 0 additions & 16 deletions packages/eslint-config-ali/test/fixtures/vue.vue

This file was deleted.

16 changes: 0 additions & 16 deletions packages/eslint-config-ali/test/self-lint.test.ts

This file was deleted.

44 changes: 0 additions & 44 deletions packages/eslint-config-ali/test/use-babel-eslint.test.xxx.ts

This file was deleted.

4 changes: 4 additions & 0 deletions packages/eslint-config-ali/tests/bad/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.js
*.jsx
*.ts
*.tsx
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import React, { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import {
Breadcrumb,
Button,
Search,
Select,
Dropdown,
Menu,
Notice,
Search,
Select,
} from "antd";
import Layout from "layout";
import { Translate } from "antd-i18n";
import Layout from "layout";
import { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import * as actions from "../actions/index";

function scoreAudioCoverFile(imgFile) {
Expand Down
15 changes: 15 additions & 0 deletions packages/eslint-config-ali/tests/good/react-hooks.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect, useMemo, useState } from 'react';

export function GoodReactHooks() {
const [foo, setFoo] = useState('foo');
const [bar, setBar] = useState('bar');

const foobar = useMemo(() => foo + bar, [foo, bar]);

useEffect(() => {
setFoo('notfoo');
setBar('notbar');
}, []);

return <div>{foobar}</div>;
}
15 changes: 15 additions & 0 deletions packages/eslint-config-ali/tests/good/react-hooks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useEffect, useMemo, useState } from 'react';

export function GoodReactHooks() {
const [foo, setFoo] = useState('foo');
const [bar, setBar] = useState('bar');

const foobar = useMemo(() => foo + bar, [foo, bar]);

useEffect(() => {
setFoo('notfoo');
setBar('notbar');
}, []);

return <div>{foobar}</div>;
}
47 changes: 47 additions & 0 deletions packages/eslint-config-ali/tests/react.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ESLint } from 'eslint';
import path from 'node:path';
import { react } from '../src';

it('should lint jsx files', async () => {
const filePath = path.join(import.meta.dirname, './bad/use-babel-eslint.jsx');

const cli = new ESLint({
baseConfig: react,
overrideConfigFile: true,
ignore: true,
});

const results = await cli.lintFiles([filePath]);
const { messages, errorCount, fatalErrorCount, warningCount } = results[0];

expect(fatalErrorCount).toBe(0);
expect(errorCount).toBe(20);
expect(warningCount).toBe(7);

const errorReportedByReactPlugin = messages.filter((result) => {
return (
(result.ruleId && result.ruleId.startsWith('react/')) ||
result.ruleId.startsWith('react-hooks/')
);
});

expect(errorReportedByReactPlugin.length).toBe(3);
});

describe('good', () => {
['react-hooks.jsx', 'react-hooks.tsx'].forEach((file) => {
it(`should pass lint for ${file}`, async () => {
const cli = new ESLint({
baseConfig: react,
overrideConfigFile: true,
ignore: true,
});

const results = await cli.lintFiles(path.join(import.meta.dirname, 'good', file));

expect(results[0].fatalErrorCount).toBe(0);
expect(results[0].errorCount).toBe(0);
expect(results[0].warningCount).toBe(0);
});
});
});
15 changes: 15 additions & 0 deletions packages/eslint-config-ali/tests/self.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ESLint } from 'eslint';
import path from 'path';
import { base } from '../src';

// Lint the package source code
it('should pass self lint', async () => {
const cli = new ESLint({
baseConfig: base,
overrideConfigFile: true,
ignore: true,
});

const reports = await cli.lintFiles([path.join(import.meta.dirname, '../src')]);
expect(reports.reduce((count, { errorCount }) => errorCount + count, 0)).toBe(0);
});
Loading

0 comments on commit d482c04

Please sign in to comment.