Ver Fonte

personal adjustments.

Shawn Lu há 1 ano atrás
pai
commit
8d958001d7
9 ficheiros alterados com 684 adições e 147 exclusões
  1. 20 2
      .eslintrc.json
  2. 0 12
      .github/FUNDING.yml
  3. 5 1
      .gitignore
  4. 1 0
      .prettierrc
  5. 18 18
      __tests__/main.test.ts
  6. 1 1
      jest.config.js
  7. 630 108
      package-lock.json
  8. 3 2
      package.json
  9. 6 3
      src/main.ts

+ 20 - 2
.eslintrc.json

@@ -10,10 +10,12 @@
     "sourceType": "module",
     "ecmaVersion": 2020
   },
-  "plugins": ["@typescript-eslint", "jest"],
+  "plugins": ["@typescript-eslint", "jest", "prettier"],
   "extends": [
     "eslint:recommended",
     "plugin:@typescript-eslint/recommended",
+    // Uncomment the following lines to enable the recommended rules for type checking.
+    //    "plugin:@typescript-eslint/recommended-requiring-type-checking",
     "plugin:jest/recommended",
     "prettier"
   ],
@@ -22,6 +24,22 @@
     // examples, and because it is not a recommended rule, you should either
     // disable it, or understand what it enforces.
     // https://typescript-eslint.io/rules/explicit-function-return-type/
-    "@typescript-eslint/explicit-function-return-type": "warn"
+    // see prettier setting in ./.prettierrc
+    "@typescript-eslint/explicit-function-return-type": "warn",
+    "@typescript-eslint/no-inferrable-types": 0,
+    "@typescript-eslint/no-unused-vars": 1,
+    "@typescript-eslint/no-var-requires": 0,
+    "@typescript-eslint/no-explicit-any": 0,
+    "no-param-reassign": 0,
+    "import/export": 0,
+    "max-len": [
+      "warn",
+      {
+        "code": 120,
+        "tabWidth": 4
+      }
+    ],
+    "no-void": 0,
+    "@typescript-eslint/ban-ts-comment": 0
   }
 }

+ 0 - 12
.github/FUNDING.yml

@@ -1,12 +0,0 @@
-# These are supported funding model platforms
-
-github: [jsynowiec]
-patreon: # Replace with a single Patreon username
-open_collective: # Replace with a single Open Collective username
-ko_fi: # Replace with a single Ko-fi username
-tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
-community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
-liberapay: # Replace with a single Liberapay username
-issuehunt: # Replace with a single IssueHunt username
-otechie: # Replace with a single Otechie username
-custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

+ 5 - 1
.gitignore

@@ -26,4 +26,8 @@ build/
 .eslintcache
 
 # Misc
-.DS_Store
+.DS_Store
+
+# Ignore all env files
+.env
+env/

+ 1 - 0
.prettierrc

@@ -1,5 +1,6 @@
 {
   "singleQuote": true,
+  "semi": false,
   "trailingComma": "all",
   "overrides": [
     {

+ 18 - 18
__tests__/main.test.ts

@@ -1,10 +1,10 @@
-import { Delays, greeter } from '../src/main.js';
+import { Delays, greeter } from '../src/main.js'
 
 describe('greeter function', () => {
-  const name = 'John';
-  let hello: string;
+  const name = 'John'
+  let hello: string
 
-  let timeoutSpy: jest.SpyInstance;
+  let timeoutSpy: jest.SpyInstance
 
   // Act before assertions
   beforeAll(async () => {
@@ -13,30 +13,30 @@ describe('greeter function', () => {
     // Jest 27 now uses "modern" implementation of fake timers
     // https://jestjs.io/blog/2021/05/25/jest-27#flipping-defaults
     // https://github.com/facebook/jest/pull/5171
-    jest.useFakeTimers();
-    timeoutSpy = jest.spyOn(global, 'setTimeout');
+    jest.useFakeTimers()
+    timeoutSpy = jest.spyOn(global, 'setTimeout')
 
-    const p: Promise<string> = greeter(name);
-    jest.runOnlyPendingTimers();
-    hello = await p;
-  });
+    const p: Promise<string> = greeter(name)
+    jest.runOnlyPendingTimers()
+    hello = await p
+  })
 
   // Teardown (cleanup) after assertions
   afterAll(() => {
-    timeoutSpy.mockRestore();
-  });
+    timeoutSpy.mockRestore()
+  })
 
   // Assert if setTimeout was called properly
   it('delays the greeting by 2 seconds', () => {
-    expect(setTimeout).toHaveBeenCalledTimes(1);
+    expect(setTimeout).toHaveBeenCalledTimes(1)
     expect(setTimeout).toHaveBeenLastCalledWith(
       expect.any(Function),
       Delays.Long,
-    );
-  });
+    )
+  })
 
   // Assert greeter result
   it('greets a user with `Hello, {name}` message', () => {
-    expect(hello).toBe(`Hello, ${name}`);
-  });
-});
+    expect(hello).toBe(`Hello, ${name}`)
+  })
+})

+ 1 - 1
jest.config.js

@@ -15,4 +15,4 @@ export default {
     '!src/**/*.d.ts',
     '!src/**/*.d.mts',
   ],
-};
+}

Diff do ficheiro suprimidas por serem muito extensas
+ 630 - 108
package-lock.json


+ 3 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "node-typescript-boilerplate",
-  "version": "0.0.0",
+  "version": "0.0.1",
   "description": "Minimalistic boilerplate to quick-start Node.js development in TypeScript.",
   "type": "module",
   "engines": {
@@ -14,6 +14,7 @@
     "eslint": "~8.46",
     "eslint-config-prettier": "~9.0",
     "eslint-plugin-jest": "~27.2",
+    "eslint-plugin-prettier": "^5.1.1",
     "jest": "~29.6",
     "prettier": "~3.0",
     "rimraf": "~5.0",
@@ -22,6 +23,7 @@
     "typescript": "~5.1"
   },
   "scripts": {
+    "prestart": "npm run build",
     "start": "node build/src/main.js",
     "clean": "rimraf coverage build tmp",
     "prebuild": "npm run lint",
@@ -33,7 +35,6 @@
     "prettier": "prettier --config .prettierrc --write .",
     "test:watch": "jest --watch"
   },
-  "author": "Jakub Synowiec <jsynowiec@users.noreply.github.com>",
   "license": "Apache-2.0",
   "dependencies": {
     "tslib": "~2.6"

+ 6 - 3
src/main.ts

@@ -20,7 +20,7 @@ function delayedHello(
 ): Promise<string> {
   return new Promise((resolve: (value?: string) => void) =>
     setTimeout(() => resolve(`Hello, ${name}`), delay),
-  );
+  )
 }
 
 // Please see the comment in the .eslintrc.json file about the suppressed rule!
@@ -28,7 +28,10 @@ function delayedHello(
 // at https://eslint.org/docs/latest/user-guide/configuring/rules#disabling-rules
 
 // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
-export async function greeter(name: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
+export async function greeter(name: any) {
+  // eslint-disable-line @typescript-eslint/no-explicit-any
   // The name parameter should be of type string. Any is used only to trigger the rule.
-  return await delayedHello(name, Delays.Long);
+  return await delayedHello(name, Delays.Medium)
 }
+
+await greeter('world').then(console.log)

Alguns ficheiros não foram mostrados porque muitos ficheiros mudaram neste diff