From b3223822bd652546c2cbc21dff90fadd9267e57b Mon Sep 17 00:00:00 2001 From: Estelle Foisy Date: Wed, 19 Apr 2023 08:34:09 -0400 Subject: [PATCH] Add Prettier to script to help enforce code style Fix the issue #861 regarding code style. --- .github/workflows/build.yml | 71 +++++++++++++++++++------------------ .prettierrc | 6 ++++ configs/base.eslintrc.json | 12 ++----- package.json | 6 ++-- 4 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 .prettierrc diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2201081a8..dce48ffdb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,12 +2,11 @@ name: build on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: - build-and-test: runs-on: ${{ matrix.os }} @@ -17,49 +16,51 @@ jobs: node-version: [16.x] steps: - - name: install dependencies on ubuntu - if: startsWith(matrix.os,'ubuntu') - run: | - sudo apt install -y make gcc pkg-config build-essential libx11-dev libxkbfile-dev + - name: install dependencies on ubuntu + if: startsWith(matrix.os,'ubuntu') + run: | + sudo apt install -y make gcc pkg-config build-essential libx11-dev libxkbfile-dev - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" - - name: Cache node_modules with yarn - uses: actions/cache@v2 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- + - name: Cache node_modules with yarn + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- - - run: yarn --frozen-lockfile + - run: yarn --frozen-lockfile - - run: yarn test - env: - CI: true + - run: yarn test + env: + CI: true code-lint: runs-on: ubuntu-latest steps: - - name: Check out Git repository - uses: actions/checkout@v2 + - name: Check out Git repository + uses: actions/checkout@v2 + + - uses: actions/setup-node@v3 + with: + node-version: '16' - - uses: actions/setup-node@v3 - with: - node-version: '16' + # ESLint and Prettier must be in `package.json` + - run: yarn --frozen-lockfile --ignore-scripts - # ESLint and Prettier must be in `package.json` - - run: yarn --frozen-lockfile --ignore-scripts + - run: yarn lint - - run: yarn lint + - run: yarn format diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..b3dc5a654 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "endOfLine": "lf", + "semi": false, + "singleQuote": true, + "trailingComma": "es5" + } diff --git a/configs/base.eslintrc.json b/configs/base.eslintrc.json index f639b7266..db014b539 100644 --- a/configs/base.eslintrc.json +++ b/configs/base.eslintrc.json @@ -7,19 +7,13 @@ "jsx": true } }, - "plugins": [ - "@typescript-eslint", - "import", - "no-null" - ], + "plugins": ["@typescript-eslint", "prettier", "import", "no-null"], + "extends": ["prettier"], "env": { "browser": true, "node": true }, - "ignorePatterns": [ - "node_modules", - "*.d.ts" - ], + "ignorePatterns": ["node_modules", "*.d.ts"], "rules": { "@typescript-eslint/no-namespace": "off" } diff --git a/package.json b/package.json index 35142a3c1..f5d660ae8 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "lint": "lerna run lint", "test": "lerna run test --", "publish:latest": "lerna publish --registry=https://registry.npmjs.org/ --exact --no-git-tag-version --no-push", - "publish:next": "lerna publish --registry=https://registry.npmjs.org/ --exact --canary minor --preid=next.$(git rev-parse --short HEAD) --dist-tag=next --no-git-tag-version --no-push --yes" + "publish:next": "lerna publish --registry=https://registry.npmjs.org/ --exact --canary minor --preid=next.$(git rev-parse --short HEAD) --dist-tag=next --no-git-tag-version --no-push --yes", + "format": "prettier \"./**/*.{ts,tsx,js,md,json}\" --write" }, "keywords": [ "theia-extension", @@ -48,7 +49,8 @@ "@theia/cli": "1.34.2", "jsonc-parser": "^3.0.0", "lerna": "^4.0.0", - "typescript": "4.5.5" + "typescript": "4.5.5", + "prettier": "^2.7.1" }, "workspaces": [ "examples/*",