Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint for TypeScript #46

Closed
tima101 opened this issue Oct 20, 2019 · 4 comments
Closed

ESLint for TypeScript #46

tima101 opened this issue Oct 20, 2019 · 4 comments
Assignees

Comments

@tima101
Copy link
Member

tima101 commented Oct 20, 2019

Things to do to enable highlighting and auto-fixing of TS code by ESLint on VS code editor:

  • install extension: dbaeumer.vscode-eslint
  • set TS parsing and proper directory by adding settings to settings.json for Workspace:
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  "editor.formatOnSave": true,
  "eslint.enable": true,
  "eslint.alwaysShowStatus": true,
  "eslint.autoFixOnSave": true,
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    { "language": "typescript", "autoFix": true },
    { "language": "typescriptreact", "autoFix": true }
  ],
  "eslint.workingDirectories": [
		{ "directory": "./book/1-end/app", "changeProcessCWD": true },
	]
  • add .eslintrc.js to the root of your project, for example ./book/1-end/app
module.exports = {
  parser: "@typescript-eslint/parser",
  extends: ["plugin:@typescript-eslint/recommended", "prettier"],
  env: {
    "es6": true,
    "node": true
  },
  rules: {
    'prettier/prettier': [
      'error',
      {
        singleQuote: true,
        trailingComma: 'all',
        arrowParens: 'always',
        printWidth: 100,
        semi: true
      },
    ],
    '@typescript-eslint/no-unused-vars': 'off',
    '@typescript-eslint/explicit-function-return-type': 'off'
 },
  plugins: [
    "prettier"
  ]
}
  • add all necessary packages to devDependencies, for ./book/1-end/app, I have:
  "devDependencies": {
    "@types/node": "12.7.9",
    "@types/react": "16.9.4",
    "@types/react-dom": "16.9.1",
    "@typescript-eslint/eslint-plugin": "^2.4.0",
    "@typescript-eslint/parser": "^2.4.0",
    "eslint": "^6.5.1",
    "eslint-config-prettier": "^6.4.0",
    "eslint-plugin-prettier": "^3.1.1",
    "prettier": "^1.18.2"
  }
  • you may need to restart VS code editor
  • you can also add command "lint": "eslint . --ext .js,.jsx,.ts,.tsx" to package.json

Highlighting by ESLint:
Screenshot from 2019-10-20 12-55-34

To fix, press Ctrl + S.

Add your own formatting rules to .eslintrc.js

@tima101 tima101 added the Assigned - Async Issue is assigned to at least one person. PR is assigned to at least one person. label Oct 20, 2019
@tima101 tima101 self-assigned this Oct 20, 2019
@tima101 tima101 added Downhill - Async Issue is being actively implemented, interruptions are discouraged. PR is under review. Ready to test - Async Issue is implemented and ready for testing. PR is merged. and removed Assigned - Async Issue is assigned to at least one person. PR is assigned to at least one person. Downhill - Async Issue is being actively implemented, interruptions are discouraged. PR is under review. labels Oct 20, 2019
@tima101
Copy link
Member Author

tima101 commented Oct 20, 2019

@delgermurun @klyburke I will close this issue when done updating all chapters and main app.

@delgermurun
Copy link
Contributor

@tima101 It works.

@tima101 tima101 closed this as completed Oct 28, 2019
@tima101 tima101 removed the Ready to test - Async Issue is implemented and ready for testing. PR is merged. label Oct 28, 2019
@zamgill
Copy link

zamgill commented Oct 30, 2019

For anyone having an issue under ./book/1-begin/app folder please add the following line in settings.json

{ "directory": "./book/1-begin/app", "changeProcessCWD": true },

@tima101
Copy link
Member Author

tima101 commented Oct 30, 2019

@zamgill Thanks.

Workspace settings for VS code editor:
https://github.com/async-labs/saas/blob/master/.vscode/settings.json

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

No branches or pull requests

3 participants