Agoric / dapp-offer-up

Offer Up is a simple Dapp for the Agoric smart contract platform that permits users to explore items for sale in a marketplace
6 stars 5 forks source link

Contract Linting: add lint:types and use @typescript/eslint-parser #35

Closed 0xpatrickdev closed 1 month ago

0xpatrickdev commented 9 months ago

Building off of #33, update the eslint configuration to use @typescript/eslint-parser. With this in place, we can use typescript to audit jsdoc typedefs and enable better code navigation (go to definition).

0xpatrickdev commented 8 months ago

See this comments for more details on a suggested eslint configuration: https://github.com/Agoric/dapp-offer-up/pull/26#discussion_r1440876220

Here would be the updated directions from the current answer:

  1. Run:

    yarn add -D \
    eslint \
    @agoric/eslint-config@dev \
    @endo/eslint-plugin \
    @jessie.js/eslint-plugin \
    eslint-config-airbnb-base \
    eslint-plugin-jsdoc \
    eslint-config-prettier \
    eslint-plugin-import \
    - eslint-plugin-github 
    + eslint-plugin-github \
    + @typescript-eslint/eslint-plugin
    + @typescript-eslint/parser
    + typescript
  2. Add the following to your package.json

    
    "eslintConfig" : {
    +  "env": {
    +    "node": true
    +  },
    +  "parser": "@typescript-eslint/parser",
    "parserOptions": {
    -      "sourceType": "module",
    -      "ecmaVersion": 6
    +    "project": "./tsconfig.json",
    +    "sourceType": "module",
    +    "ecmaVersion": 2020
    },
    "extends": [
    +    "plugin:@typescript-eslint/recommended",
     "@agoric"
    ],
    +  "plugins": [
    +    "@typescript-eslint",
    +    "prettier"
    +  ],
    +  "rules": {
    +    "@typescript-eslint/no-floating-promises": "warn",
    +    "no-void": [
    +      "error",
    +      {
    +        "allowAsStatement": true
    +      }
    +    ],
    +    "prettier/prettier": "warn",
    +    "@typescript-eslint/no-unused-vars": [
    +      "error",
    +      {
    +        "vars": "all",
    +        "args": "all",
    +        "argsIgnorePattern": "^_",
    +        "varsIgnorePattern": "^_"
    +      }
    +    ]
    +  },
    }
3. Add a tsconfig.json file (new)
```diff
+{
+  "compilerOptions": {
+    "noEmit": true,
+    "target": "esnext",
+    "module": "esnext",
+    "moduleResolution": "node",
+    "skipLibCheck": true,
+    "checkJs": false,
+    "allowJs": true,
+    "allowSyntheticDefaultImports": true,
+    "maxNodeModuleJsDepth": 2,
+    "strict": true
+  },
+  "include": ["**/*.js", "**/*.ts"],
+  "exclude": ["bundles"]
+}
  1. Run yarn eslint '**/*.{js,ts}' (or specify other files/directory globs). Run yarn tsc to lint types.