Skip to content

Commit

Permalink
Merge pull request #229 from lishaduck/attw
Browse files Browse the repository at this point in the history
Are the types wrong?
  • Loading branch information
AndreaPontrandolfo authored Aug 25, 2024
2 parents 1484efe + dad6ad9 commit ff57cfc
Show file tree
Hide file tree
Showing 23 changed files with 761 additions and 1,085 deletions.
13 changes: 13 additions & 0 deletions .changeset/tiny-toes-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'eslint-config-sheriff': minor
'@sherifforg/constants': minor
'@sherifforg/types': minor
'@sherifforg/cli': minor
'tsconfig': minor
'sheriff-webservices': patch
---

feat!: esm-only bundling (follow up to #225)
fix: don't bundle node_modules
fix: webservices types
feat!: enable verbatimModuleSyntax
1 change: 1 addition & 0 deletions apps/cli-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "cli-playground",
"version": "0.0.0",
"description": "Playground for playtesting create-eslint-config.",
"private": true,
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions apps/config-validation-playground/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "config-validation-playground",
"version": "0.0.0",
"description": "Playground for validating eslint-config-sheriff.",
"private": true,
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion apps/docs-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/AndreaPontrandolfo/sheriff.git",
"url": "git+https://github.com/AndreaPontrandolfo/sheriff.git",
"directory": "apps/docs-website"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion apps/sheriff-webservices/src/generateRulesDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const extractNumericSeverityFromRuleOptions = (
return severityRemapper(ruleOptions[0]);
}

return severityRemapper(ruleOptions);
return severityRemapper(ruleOptions ?? 'off');
};

const getCompiledConfig = (
Expand Down
29 changes: 12 additions & 17 deletions apps/sheriff-webservices/src/getAllRules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import type { ESLint } from 'eslint';
import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import astro from 'eslint-plugin-astro';
Expand All @@ -18,7 +17,7 @@ import storybook from 'eslint-plugin-storybook';
import tsdoc from 'eslint-plugin-tsdoc';
import unicorn from 'eslint-plugin-unicorn';
import tseslint from 'typescript-eslint';
import eslintRecommended from '@eslint/js';
import eslintJs from '@eslint/js';
import rel1cxReact from '@eslint-react/eslint-plugin';
import nextjs from '@next/eslint-plugin-next';
import preferEarlyReturn from '@regru/eslint-plugin-prefer-early-return';
Expand All @@ -42,20 +41,20 @@ export const getAllRules = (
) => Record<string, RuleOptions>,
): BarebonesConfigAtom['rules'] => {
const reactRulesCatalog = {
//@ts-expect-error
...react.configs.flat.recommended.rules,
//@ts-expect-error
...react.configs.flat['jsx-runtime'].rules,
...prependRulesWithPluginName(reactAccessibility.rules, 'jsx-a11y'),
...prependRulesWithPluginName(reactHooks.rules, 'react-hooks'),
...prependRulesWithPluginName(reactRefresh.rules, 'react-refresh'),
//@ts-expect-error
...prependRulesWithPluginName(rel1cxReact.rules, '@eslint-react'),
...prependRulesWithPluginName(
(rel1cxReact as unknown as Plugin).rules,
'@eslint-react',
),
...prependRulesWithPluginName(fsecond.rules, 'fsecond'),
};

const rules: BarebonesConfigAtom['rules'] = {
...eslintRecommended.rules,
...eslintJs.configs.all.rules,
...prependRulesWithPluginName(
//@ts-expect-error
tseslint.plugin.rules ?? [],
Expand All @@ -65,23 +64,22 @@ export const getAllRules = (
//@ts-expect-error
...prependRulesWithPluginName(sonarjs.rules, 'sonarjs'),
...prependRulesWithPluginName(jsdoc.rules, 'jsdoc'),
...prependRulesWithPluginName((tsdoc as unknown as Plugin).rules, 'tsdoc'),
...prependRulesWithPluginName(tsdoc.rules, 'tsdoc'),
...prependRulesWithPluginName(
preferEarlyReturn.rules,
'@regru/prefer-early-return',
),
...prependRulesWithPluginName(
(arrowReturnStyle as unknown as Plugin).rules,
'arrow-return-style',
),
...prependRulesWithPluginName(arrowReturnStyle.rules, 'arrow-return-style'),
// Stylistic's types are wrong, `default` should not be needed.
// Oh well. Casting it is, I guess.
...prependRulesWithPluginName(
(stylistic as unknown as Plugin).rules,
'@stylistic',
),
...prependRulesWithPluginName(simpleImportSort.rules, 'simple-import-sort'),
...prependRulesWithPluginName(pluginImport.rules, 'import'),
...prependRulesWithPluginName(storybook.rules, 'storybook'),
...prependRulesWithPluginName((astro as unknown as Plugin).rules, 'astro'),
...prependRulesWithPluginName(astro.rules, 'astro'),
...(settings.react ? reactRulesCatalog : {}),
...(settings.next
? prependRulesWithPluginName(nextjs.rules, '@next/next')
Expand All @@ -94,10 +92,7 @@ export const getAllRules = (
: {}),
...(settings.jest ? prependRulesWithPluginName(jest.rules, 'jest') : {}),
...(settings.vitest
? prependRulesWithPluginName(
(vitest as unknown as Plugin).rules,
'vitest',
)
? prependRulesWithPluginName(vitest.rules, 'vitest')
: {}),
};

Expand Down
65 changes: 6 additions & 59 deletions apps/sheriff-webservices/src/handledModules.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */

declare module '@eslint/js' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module '@next/eslint-plugin-next' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
Expand All @@ -21,27 +12,6 @@ declare module '@regru/eslint-plugin-prefer-early-return' {

export default config;
}
declare module 'eslint-plugin-unicorn' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-playwright' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-jsdoc' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-lodash-f' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
Expand Down Expand Up @@ -73,27 +43,12 @@ declare module 'eslint-plugin-storybook' {
declare module 'eslint-plugin-react*' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-jsx-a11y' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-react-hooks' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
};

export default config;
}
declare module 'eslint-plugin-react-refresh' {
const config: {
rules: Record<string, import('@sherifforg/types').RuleOptions>;
configs: {
flat: Record<
string,
{ rules: Record<string, import('@sherifforg/types').RuleOptions> }
>;
};
};

export default config;
Expand All @@ -105,11 +60,3 @@ declare module 'eslint-plugin-fsecond' {

export default config;
}
declare module 'eslint-config-sheriff' {
const config: (
userConfigChoices: import('@sherifforg/types').SheriffSettings,
areAllRulesForced?: boolean,
) => import('@sherifforg/types').ExportableConfigAtom[];

export default config;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"typesync": "turbo run typesync",
"knip": "knip",
"validate-config": "turbo run validate-config",
"merge-checks": "turbo run publint manypkg typesync knip typecheck lint validate-config check-deduped-deps",
"merge-checks": "turbo run publint manypkg typesync knip typecheck lint validate-config check-deduped-deps are-the-types-wrong",
"check-deduped-deps": "pnpm dedupe --check",
"clean": "turbo run clean && rm -rf .turbo",
"delete-node-modules": "pnpm exec rm -rf node_modules && pnpm -r exec rm -rf node_modules",
Expand Down
10 changes: 3 additions & 7 deletions packages/eslint-config-sheriff/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
"name": "eslint-config-sheriff",
"version": "21.0.0",
"description": "A comprehensive and opinionated Typescript-first ESLint configuration.",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
Expand All @@ -24,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/AndreaPontrandolfo/sheriff.git",
"url": "git+https://github.com/AndreaPontrandolfo/sheriff.git",
"directory": "packages/eslint-config-sheriff"
},
"keywords": [
Expand Down Expand Up @@ -53,7 +49,7 @@
"typecheck": "tsc --noEmit",
"publint": "publint",
"typesync": "typesync --dry=fail",
"are-the-types-wrong": "attw --pack ."
"are-the-types-wrong": "attw $(pnpm pack) --ignore-rules cjs-resolves-to-esm no-resolution && rm eslint-config-sheriff-*.tgz"
},
"dependencies": {
"@eslint-react/eslint-plugin": "^1.10.1",
Expand Down Expand Up @@ -107,7 +103,7 @@
"lodash": "^4.17.21",
"publint": "^0.2.10",
"tsconfig": "workspace:*",
"tsup": "^6.2.3",
"tsup": "^8.2.4",
"typescript": "^5.5.3"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-sheriff/src/getBaseConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import fsecond from 'eslint-plugin-fsecond';
import arrowReturnStyle from 'eslint-plugin-arrow-return-style';
import stylistic from '@stylistic/eslint-plugin';
import { supportedFileTypes, allJsExtensions } from '@sherifforg/constants';
import { SheriffSettings } from '@sherifforg/types';
import type { SheriffSettings } from '@sherifforg/types';
import { getTsNamingConventionRule } from './utils/getTsNamingConventionRule';
import { importHandPickedRules } from './handpickedRules/importHandPickedRules';
import { jsdocHandPickedRules } from './handpickedRules/jsdocHandPickedRules';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-sheriff/src/getExportableConfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getGitignorePatterns from 'eslint-config-flat-gitignore';
import lodash from 'lodash';
import type { FlatESLintConfig } from 'eslint-define-config';
import { SheriffSettings } from '@sherifforg/types';
import type { SheriffSettings } from '@sherifforg/types';
import { ignores, sheriffStartingOptions } from '@sherifforg/constants';
import { getReactConfig } from './getReactConfig';
import { getBaseConfig } from './getBaseConfig';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const getLanguageOptionsTypescript = (
return {
parser: tseslint.parser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { modules: true },
project: userChosenTSConfig || true,
},
Expand Down
11 changes: 8 additions & 3 deletions packages/eslint-config-sheriff/tsup.config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"entry": ["./src/index.ts"],
"format": ["esm", "cjs"],
"dts": true,
"format": "esm",
"dts": {
"entry": "src/index.ts",
"resolve": ["@sherifforg/constants"]
},
"splitting": false,
"sourcemap": false,
"clean": true
"clean": true,
"noExternal": ["@sherifforg/constants"],
"skipNodeModulesBundle": true
}
9 changes: 4 additions & 5 deletions packages/sheriff-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"version": "7.0.0",
"type": "module",
"description": "The Sheriff CLI. Used to create and manage Sheriff-based ESLint configs.",
"main": "dist/index.js",
"scripts": {
"dev": "tsx ./src/index.ts",
"clean": "rm -rf .turbo dist",
Expand All @@ -26,8 +25,8 @@
"yargs": "^17.7.2"
},
"bin": {
"create-sheriff-config": "./dist/index.js",
"sheriff": "./dist/index.js"
"create-sheriff-config": "dist/index.js",
"sheriff": "dist/index.js"
},
"devDependencies": {
"@sherifforg/constants": "workspace:*",
Expand All @@ -40,12 +39,12 @@
"eslint-define-config": "^2.1.0",
"publint": "^0.2.10",
"tsconfig": "workspace:*",
"tsup": "^6.2.3",
"tsup": "^8.2.4",
"tsx": "^4.16.2"
},
"repository": {
"type": "git",
"url": "https://github.com/AndreaPontrandolfo/sheriff.git",
"url": "git+https://github.com/AndreaPontrandolfo/sheriff.git",
"directory": "packages/sheriff-cli"
},
"author": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sheriff-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"extends": "tsconfig/base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"incremental": true,
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
"resolveJsonModule": true
Expand Down
22 changes: 4 additions & 18 deletions packages/sheriff-constants/package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
{
"name": "@sherifforg/constants",
"description": "Sheriff constants variables.",
"description": "Sheriff constants.",
"version": "0.0.4",
"private": true,
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
".": "./src/index.ts"
},
"files": [
"dist",
"src",
"CHANGELOG.md"
],
"scripts": {
"publint": "publint",
"clean": "rm -rf .turb dist",
"build": "tsup",
"are-the-types-wrong": "attw --pack ."
"clean": "rm -rf .turbo"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.15.4",
"@sherifforg/types": "workspace:*",
"publint": "^0.2.10",
"tsconfig": "workspace:*",
"typescript": "^5.5.3"
},
"dependencies": {
"tsup": "^6.2.3"
}
}
2 changes: 1 addition & 1 deletion packages/sheriff-constants/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SheriffConfigurablePlugins } from '@sherifforg/types';
import type { SheriffConfigurablePlugins } from '@sherifforg/types';

export const sheriffStartingOptions: SheriffConfigurablePlugins = {
react: false,
Expand Down
Loading

0 comments on commit ff57cfc

Please sign in to comment.