Skip to content

Conversation

github-actions[bot]
Copy link

Closes #497

Applied changes based on Issue #497.

I’ve centralized all of the “hidden” magic values into named constants, documented defaults in our config schema, and made the loading‑phrases list explicitly readonly with its own JSDoc. Here’s what changed:


1. Pull magic numbers out of .eslintrc.js

Defined MAX_LINE_LENGTH and MAX_LINE_LENGTH_TEST at the top of the ESLint config and replaced the hard‑coded 80/120:

/** ESLint configuration constants to avoid magic numbers. */
/** Maximum allowed line length for source code. */
const MAX_LINE_LENGTH = 80;
/** Maximum allowed line length for test files. */
const MAX_LINE_LENGTH_TEST = 120;

module.exports = {
  // …
  rules: {
    // …
-   'max-len': ['error', { code: 80, ignoreComments: false }],
+   'max-len': ['error', { code: MAX_LINE_LENGTH, ignoreComments: false }],
    // …
  },
  overrides: [
    {
      files: ['**/__tests__/**/*.{js,jsx,ts,tsx}'],
-     rules: {
-       'max-len': ['error', { code: 120, ignoreComments: false }],
+     rules: {
+       'max-len': ['error', { code: MAX_LINE_LENGTH_TEST, ignoreComments: false }],
        '@typescript-eslint/no-explicit-any': 'off',
      },
    },
  ],
};

【F:.eslintrc.js†L1-L11】【F:.eslintrc.js†L34-L37】【F:.eslintrc.js†L94-L97】


2. Add default‑value constants in src/constants.ts

Introduced DEFAULT_TIMEOUT_SECONDS and DEFAULT_WORKSPACE_PATH so these aren’t buried in code:

export const PROGRESS_TITLE = '**🚀 Codez Progress**';

/** Default timeout for GitHub Action in seconds. */
export const DEFAULT_TIMEOUT_SECONDS = 600;

/** Default workspace path for the GitHub Action. */
export const DEFAULT_WORKSPACE_PATH = '/workspace/app';

/** Loading phrases to display below the progress bar. */
export { default as LOADING_PHRASES } from './loadingPhrases.ts';

【F:src/constants.ts†L13-L20】


3. Wire those defaults through src/config/config.ts

  • Imported the new constants.
  • Replaced literal '/workspace/app' and 600 with DEFAULT_WORKSPACE_PATH / DEFAULT_TIMEOUT_SECONDS.
  • Documented those defaults in the ActionConfig interface with JSDoc.
-import { DEFAULT_TRIGGER_PHRASE } from '../constants';
+import {
+  DEFAULT_TRIGGER_PHRASE,
+  DEFAULT_TIMEOUT_SECONDS,
+  DEFAULT_WORKSPACE_PATH,
+} from '../constants';

 export interface ActionConfig {
   githubToken: string;
   eventPath: string;
+  /**
+   * GitHub workspace path.
+   * @default DEFAULT_WORKSPACE_PATH
+   */
   workspace: string;
+  /**
+   * Timeout in seconds for GitHub Action operations.
+   * @default DEFAULT_TIMEOUT_SECONDS
+   */
   timeoutSeconds: number;
   octokit: Octokit;
   context: typeof github.context;
   repo: { owner: string; repo: string };

 export function getConfig(): ActionConfig {
-  const workspace = '/workspace/app';
+  const workspace = DEFAULT_WORKSPACE_PATH;
   const timeoutInput = core.getInput('timeout');
   let timeoutSeconds: number;
   if (timeoutInput) {
     // … validation …
   } else {
-    timeoutSeconds = 600;
+    timeoutSeconds = DEFAULT_TIMEOUT_SECONDS;
   }
   // …
 }

【F:src/config/config.ts†L10-L16】【F:src/config/config.ts†L28-L37】【F:src/config/config.ts†L189-L200】


4. Make the loading‑phrases list explicitly readonly and document it

Added a file‑level JSDoc block and changed the array type to readonly string[]:

-const LOADING_PHRASES: string[] = [
+/**
+ * Loading phrases to display below the progress bar.
+ * These phrases are chosen at random during action execution progress updates.
+ */
+const LOADING_PHRASES: readonly string[] = [
   'Decrypting punchlines with 256-bit humor...',
   // … more phrases …
];

【F:src/loadingPhrases.ts†L1-L8】


These changes centralize all of the previously “magic” values into named, documented constants and make the defaults explicit in our configuration types. Let me know if any tweaks are needed!

@YiweiShen YiweiShen merged commit 7cd086e into main Jul 20, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-497-refactor-remove-magic-values-and-implicit-patterns-3094686140 branch July 20, 2025 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Magic values and implicit patterns

1 participant