diff --git a/.eslintrc.yml b/.eslintrc.yml index 5be2470e..03f3b1d4 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -141,13 +141,9 @@ rules: overrides: - files: - - project.config.cjs - - commitlint.config.cjs - - dangerfile.cjs - parserOptions: - sourceType: commonjs - env: - node: true + - project.config.ts + - commitlint.config.ts + - dangerfile.ts rules: 'import/no-default-export': - off diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index 7b475506..72ddd207 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -44,7 +44,7 @@ jobs: - name: Lint Commits run: | - npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose -g ./commitlint.config.cjs + npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose -g ./commitlint.config.ts - name: Add Folder Labels uses: actions/labeler@v4 diff --git a/commitlint.config.cjs b/commitlint.config.ts similarity index 88% rename from commitlint.config.cjs rename to commitlint.config.ts index f052e843..d19c4530 100644 --- a/commitlint.config.cjs +++ b/commitlint.config.ts @@ -1,4 +1,6 @@ -const { ProjectPrefix } = require('./project.config.cjs'); +import { UserConfig } from '@commitlint/types'; + +import { ProjectPrefix } from './project.config'; const COMMIT_MODIFIERS = ['+', '*', '-']; const COMMIT_MESSAGE_REGEXP = new RegExp( @@ -19,7 +21,7 @@ Examples: - ${ProjectPrefix.APP}-12: * docker homework - production: - comments in ui/ux homework`; -const configuration = { +const configuration: UserConfig = { parserPreset: { parserOpts: { headerPattern: COMMIT_MESSAGE_REGEXP, @@ -45,4 +47,4 @@ const configuration = { } }; -module.exports = configuration; +export default configuration; diff --git a/dangerfile.cjs b/dangerfile.ts similarity index 70% rename from dangerfile.cjs rename to dangerfile.ts index 6f51bff5..9177c165 100644 --- a/dangerfile.cjs +++ b/dangerfile.ts @@ -1,11 +1,29 @@ -const { danger, fail } = require('danger'); - -const { ProjectPrefix } = require('./project.config.cjs'); +import { + danger, + fail, + type GitHubPRDSL as LibraryGitHubDSL, + GitHubMergeRef, + GitHubRepo, + GitHubDSL +} from 'danger'; + +import { ProjectPrefix } from './project.config'; + +type GitHubPRDSL = LibraryGitHubDSL & { + head: GitHubMergeRef & { + repo: GitHubRepo & { + has_projects: boolean; + }; + }; + milestone: Record | null; + labels: unknown[]; + project_id: string | null; +}; const BranchPrefix = { TASK: 'task', FIX: 'fix' -}; +} as const; const DangerConfig = { TITLE: { @@ -34,9 +52,9 @@ const DangerConfig = { } }; -const pr = danger.github.pr; +const { pr } = danger.github as GitHubDSL & Record<'pr', GitHubPRDSL>; -const checkAssignees = () => { +const checkAssignees = (): void => { const hasAssignees = Boolean(pr.assignee); if (!hasAssignees) { @@ -44,7 +62,7 @@ const checkAssignees = () => { } }; -const checkTitle = titlePattern => { +const checkTitle = (titlePattern: RegExp): void => { const isTitleValid = titlePattern.test(pr.title); if (!isTitleValid) { @@ -56,7 +74,7 @@ const checkTitle = titlePattern => { } }; -const checkLabels = () => { +const checkLabels = (): void => { const hasLabels = pr.labels.length > 0; if (!hasLabels) { @@ -64,7 +82,7 @@ const checkLabels = () => { } }; -const checkBranch = branchPattern => { +const checkBranch = (branchPattern: RegExp): void => { const isBranchValid = branchPattern.test(pr.head.ref); if (!isBranchValid) { @@ -76,7 +94,7 @@ const checkBranch = branchPattern => { } }; -const applyDanger = () => { +const applyDanger = (): void => { if (DangerConfig.TITLE.IS_REQUIRED) { checkTitle(DangerConfig.TITLE.PATTERN); } diff --git a/package.json b/package.json index 42525b52..01a7fa95 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,6 @@ "node": "18.x.x", "npm": "9.x.x" }, - "type": "module", "workspaces": [ "client", "server", @@ -48,6 +47,6 @@ }, "simple-git-hooks": { "pre-commit": "npx lint-staged", - "commit-msg": "npx commitlint --edit $1 -c -g ./commitlint.config.cjs" + "commit-msg": "npx commitlint --edit $1" } } diff --git a/project.config.cjs b/project.config.ts similarity index 68% rename from project.config.cjs rename to project.config.ts index c571b1d7..1074f0fb 100644 --- a/project.config.cjs +++ b/project.config.ts @@ -1,6 +1,6 @@ const ProjectPrefix = { APP: 'thjs', ENVIRONMENTS: ['development', 'production'] -}; +} as const; -module.exports = { ProjectPrefix }; +export { ProjectPrefix }; diff --git a/tsconfig.json b/tsconfig.json index a1964dd0..7f4c0b34 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,4 @@ { - "exclude": ["commitlint.config.ts"], "compilerOptions": { "strict": true, "noUncheckedIndexedAccess": true,