Skip to content

Commit

Permalink
🐛 fix: some rules
Browse files Browse the repository at this point in the history
Signed-off-by: Pauline <[email protected]>
  • Loading branch information
pauliesnug committed Sep 16, 2024
1 parent a8c20a7 commit 48e42d9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/eslint-config/src/configs/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export async function markdown(options: OptionsMarkdown = {}): Promise<TypedFlat

'style/eol-last': 'off',
'ts/consistent-type-imports': 'off',
'ts/explicit-function-return-type': 'off',
'ts/no-namespace': 'off',
'ts/no-redeclare': 'off',
'ts/no-require-imports': 'off',
Expand Down
7 changes: 6 additions & 1 deletion packages/eslint-config/src/configs/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ export async function typescript(options: OptionsTypeScript = {}): Promise<Typed
'ts/no-import-type-side-effects': 'error',
'ts/no-invalid-void-type': 'off',
'ts/no-non-null-assertion': 'off',
'ts/no-redeclare': 'error',
'ts/no-redeclare': ['error', { builtinGlobals: false }],
'ts/no-require-imports': 'error',
'ts/no-unused-expressions': ['error', {
allowShortCircuit: true,
allowTaggedTemplates: true,
allowTernary: true,
}],
'ts/no-unused-vars': 'off',
'ts/no-use-before-define': ['error', { classes: false, functions: false, variables: true }],
'ts/no-useless-constructor': 'off',
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config/src/globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export const GLOB_HTML = '**/*.htm?(l)';
export const GLOB_BIN = '**/bin/**/*';
export const GLOB_BIN_SRC = `**/bin.${GLOB_SRC_EXT}`;
export const GLOB_SCRIPTS = `**/scripts/${GLOB_SRC}`;
export const GLOB_CLI = `cli/${GLOB_SRC}`;
export const GLOB_CLI_SRC = `cli.${GLOB_SRC_EXT}`;
export const GLOB_CLI = `**/cli/${GLOB_SRC}`;
export const GLOB_CLI_SRC = `**/cli.${GLOB_SRC_EXT}`;

// @keep-sorted
export const GLOB_UNIT_TESTS = [
Expand Down
6 changes: 3 additions & 3 deletions packages/eslint-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

export * from './configs';
export * from './factory';
export { defineConfig as default } from './factory';
export * from './globs';
export type * from './types';

export * from './utils';

export type * from './types';
export { defineConfig as default } from './factory';
4 changes: 2 additions & 2 deletions packages/eslint-config/src/types/configs/accessibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export interface OptionsAccessibility {
* Enable accessibility rules.
*
* Requires installing:
* - `eslint-plugin-jsx-a11y` on JSX
* - `eslint-plugin-vuejs-accessibility` on Vue
* - `eslint-plugin-jsx-a11y` for JSX
* - `eslint-plugin-vuejs-accessibility` for Vue
*
* @see https://github.com/jsx-eslint/eslint-plugin-jsx-a11y
* @see https://github.com/vue-a11y/eslint-plugin-vuejs-accessibility
Expand Down
22 changes: 11 additions & 11 deletions packages/eslint-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ export const toArray = <T>(value: T | T[]): T[] => Array.isArray(value) ? value
*
* export default [{
* plugins: {
* 'mine': myPlugin,
* 'mine1': myPlugin1,
* 'mine2': myPlugin2,
* mine: myPlugin,
* mine1: myPlugin1,
* mine2: myPlugin2,
* },
* }];
* ```
Expand Down Expand Up @@ -177,24 +177,24 @@ export const isPackageInScope = (name: string): boolean => isPackageExists(name,
* const chalk = interopDefault(import('chalk')); // ensures that the package is installed. add as devDependency for types
* ```
*/
export async function ensurePackages(packages: (string | undefined)[]): Promise<void> {
export async function ensurePackages(packages: string[]): Promise<void> {
if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false)
return;

const nonExistingPackages = packages.filter(i => i && !isPackageInScope(i)) as string[];
const packageExists = (i: string) => !isPackageInScope(i);
const nonExistingPackages = packages.filter(packageExists);

if (nonExistingPackages.length === 0)
return;

const result = await (await import('@clack/prompts')).confirm({
message: `${nonExistingPackages.length === 1 ? 'Package is' : 'Packages are'} required for this config: ${nonExistingPackages.join(', ')}. Do you want to install them?`,
});
if (result)
await import('@antfu/install-pkg').then(i => i.installPackage(nonExistingPackages, { dev: true }));
const message = `${nonExistingPackages.length === 1 ? 'Package is' : 'Packages are'} required for this config: ${nonExistingPackages.join(', ')}. Do you want to install them?`;
const installMissing = async () => await import('@antfu/install-pkg').then(i => i.installPackage(nonExistingPackages, { dev: true }));

if (await (await import('@clack/prompts')).confirm({ message }))
installMissing();
}

export type ResolveOptions<T> = T extends boolean ? never : NonNullable<T>;

export function resolveSubOptions<K extends keyof OptionsConfig>(options: OptionsConfig, key: K): ResolveOptions<OptionsConfig[K]> {
return typeof options[key] === 'boolean' ? {} as any : options[key] || {};
}
Expand Down

0 comments on commit 48e42d9

Please sign in to comment.