From 789faff859736244f2a39f80900211ae57e6c42d Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Thu, 1 Feb 2024 19:49:01 +0800 Subject: [PATCH] Enforce prettier in CI (#1804) * Enforce prettier in CI * Apply prettier * Automatically apply prettier before committing --- .github/ISSUE_TEMPLATE.md | 1 - .github/dependabot.yml | 13 +- .github/workflows/ci.yml | 1 + .github/workflows/release-drafter.yml | 6 +- .husky/pre-commit | 1 + README.md | 104 ++- apps/ng2-charts-demo/e2e/ng2-charts.spec.ts | 36 +- apps/ng2-charts-demo/jest.config.ts | 6 +- apps/ng2-charts-demo/playwright.config.ts | 28 +- .../app/bar-chart/bar-chart.component.spec.ts | 2 +- .../src/app/bar-chart/bar-chart.component.ts | 18 +- .../bubble-chart/bubble-chart.component.html | 3 +- .../bubble-chart.component.spec.ts | 2 +- .../bubble-chart/bubble-chart.component.ts | 14 +- .../app/chart-host/chart-host.component.ts | 37 +- .../doughnut-chart.component.spec.ts | 2 +- .../doughnut-chart.component.ts | 12 +- .../dynamic-chart.component.spec.ts | 2 +- .../dynamic-chart/dynamic-chart.component.ts | 10 +- .../financial-chart.component.spec.ts | 8 +- .../financial-chart.component.ts | 18 +- .../line-chart/line-chart.component.spec.ts | 2 +- .../app/line-chart/line-chart.component.ts | 12 +- .../app/pie-chart/pie-chart.component.spec.ts | 2 +- .../src/app/pie-chart/pie-chart.component.ts | 12 +- .../polar-area-chart.component.spec.ts | 2 +- .../polar-area-chart.component.ts | 12 +- .../radar-chart/radar-chart.component.spec.ts | 2 +- .../app/radar-chart/radar-chart.component.ts | 12 +- .../scatter-chart/scatter-chart.component.ts | 12 +- apps/ng2-charts-demo/src/index.html | 2 +- apps/ng2-charts-demo/src/types.d.ts | 10 +- apps/ng2-charts-demo/tsconfig.json | 10 +- copy-sources.mjs | 32 +- .../src/ng-add/index.spec.ts | 2 +- .../src/ng-add/setup-project.spec.ts | 8 +- .../src/utils/package-config.ts | 8 +- .../src/utils/testing.ts | 4 +- libs/ng2-charts-schematics/tsconfig.json | 10 +- libs/ng2-charts/README.md | 92 ++- .../src/lib/base-chart.directive.spec.ts | 2 +- .../src/lib/base-chart.directive.ts | 3 +- libs/ng2-charts/src/lib/get-colors.ts | 37 +- libs/ng2-charts/tsconfig.json | 6 +- libs/ng2-charts/tsconfig.lib.json | 2 +- package-lock.json | 633 ++++++++++++++++++ package.json | 11 +- tsconfig.base.json | 18 +- 48 files changed, 966 insertions(+), 316 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 30ca95b9..30dc0a46 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -6,4 +6,3 @@ Pure Chart.js starting template: https://jsfiddle.net/Hongbo_Miao/mvct2uwo/3/ If the issue does not show in a pure Chart.js project, and shows in a ng2-charts project, please try to provide a minimal demo of the problem. ng2-charts starting template: http://plnkr.co/edit/Ka4NXG3pZ1mXnaN95HX5?p=preview - diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 32250fda..2621afbe 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,13 +2,12 @@ version: 2 updates: - - - package-ecosystem: "github-actions" - directory: "/" + - package-ecosystem: 'github-actions' + directory: '/' schedule: # Check for updates to GitHub Actions every weekday - interval: "daily" - - package-ecosystem: "npm" - directory: "/" + interval: 'daily' + - package-ecosystem: 'npm' + directory: '/' schedule: - interval: "daily" + interval: 'daily' diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5db13b1..c6a86e85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: node-version: 18 - run: npm ci + - run: npx prettier --check . - run: npm run lint - run: npm run build:lib - run: npm run build:schematics diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 75331d19..52dbdd9c 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -10,9 +10,9 @@ jobs: correct_repository: runs-on: ubuntu-latest steps: - - name: fail on fork - if: github.repository_owner != 'valor-software' - run: exit 1 + - name: fail on fork + if: github.repository_owner != 'valor-software' + run: exit 1 update_release_draft: needs: correct_repository diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..2312dc58 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged diff --git a/README.md b/README.md index 68174dca..5ecfca48 100644 --- a/README.md +++ b/README.md @@ -25,79 +25,69 @@ changes to start using the library right away. 1. You can install **_ng2-charts_** using npm: - ```bash - npm install ng2-charts --save - ``` + ```bash + npm install ng2-charts --save + ``` or yarn: - ```bash - yarn add ng2-charts --save - ``` + ```bash + yarn add ng2-charts --save + ``` 2. You will also need to install and include `Chart.js` library in your application (it is a peer dependency of this library, more info can be found in the official `chart.js` [documentation](http://www.chartjs.org/docs/#getting-started)) - ```bash - npm install chart.js --save - ``` + ```bash + npm install chart.js --save + ``` or with yarn: - ```bash - yarn add chart.js --save - ``` + ```bash + yarn add chart.js --save + ``` 3. Import the directive in your standalone component: - ```typescript - import { BaseChartDirective } from 'ng2-charts'; - - @Component({ - standalone: true, - imports: [BaseChartDirective], - }) - export class MyComponent { } - ``` + ```typescript + import { BaseChartDirective } from 'ng2-charts'; + + @Component({ + standalone: true, + imports: [BaseChartDirective], + }) + export class MyComponent {} + ``` 4. Provide a configuration, typically in your `main.ts`: - ```typescript - import { - provideCharts, - withColorGenerator, - withDefaultRegisterables, - } from 'ng2-charts'; - - bootstrapApplication(AppComponent, { - providers: [ - provideCharts(withDefaultRegisterables(), withColorGenerator()), - ], - }).catch((err) => console.error(err)); - ``` - - Alternatively, include a minimal configuration to reduce the bundle size, eg: - - ```typescript - provideCharts({registerables: [BarController, Legend, Colors]}) - ``` - - Or in your AppModule: - - ```typescript - import { - provideCharts, - withColorGenerator, - withDefaultRegisterables, - } from 'ng2-charts'; - - @NgModule({ - providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())], - bootstrap: [AppComponent], - }) - export class AppModule {} - ``` + ```typescript + import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts'; + + bootstrapApplication(AppComponent, { + providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())], + }).catch((err) => console.error(err)); + ``` + + Alternatively, include a minimal configuration to reduce the bundle size, eg: + + ```typescript + provideCharts({ registerables: [BarController, Legend, Colors] }); + ``` + + Or in your AppModule: + + ```typescript + import { provideCharts, withColorGenerator, withDefaultRegisterables } from 'ng2-charts'; + + @NgModule({ + providers: [provideCharts(withDefaultRegisterables(), withColorGenerator())], + bootstrap: [AppComponent], + }) + export class AppModule {} + ``` ### Angular version compatibility table @@ -334,4 +324,4 @@ text) If you like this library and want to say thanks, consider [buying me a coffee](https://www.buymeacoffee.com/santam)! [//]: # 'super hidden section about running `npm test:ci` in win11 wsl2' -[//]: # 'export CHROME_BIN=/mnt/c/Program\\ Files\ (x86)/Google/Chrome/Application/chrome.exe' +[//]: # 'export CHROME_BIN=/mnt/c/Program\\ Files\\ (x86)/Google/Chrome/Application/chrome.exe' diff --git a/apps/ng2-charts-demo/e2e/ng2-charts.spec.ts b/apps/ng2-charts-demo/e2e/ng2-charts.spec.ts index 87e42487..14aacd2a 100644 --- a/apps/ng2-charts-demo/e2e/ng2-charts.spec.ts +++ b/apps/ng2-charts-demo/e2e/ng2-charts.spec.ts @@ -1,9 +1,9 @@ -import { test, expect } from "@playwright/test"; +import { test, expect } from '@playwright/test'; test(`navigate to main Demo page and check info`, async ({ page }) => { - const topBarSelector = "mat-toolbar"; - const mainContentSelector = "main"; - await page.goto("/"); + const topBarSelector = 'mat-toolbar'; + const mainContentSelector = 'main'; + await page.goto('/'); // wait for animations to finish await expect(page.locator(topBarSelector)).toBeVisible(); @@ -14,25 +14,27 @@ test(`navigate to main Demo page and check info`, async ({ page }) => { }); const componentsArray = [ - { url: "/#LineChart", selector: "app-line-chart" }, - { url: "/#BarChart", selector: "app-bar-chart" }, - { url: "/#DoughnutChart", selector: "app-doughnut-chart" }, - { url: "/#RadarChart", selector: "app-radar-chart" }, - { url: "/#PieChart", selector: "app-pie-chart" }, - { url: "/#PolarAreaChart", selector: "app-polar-area-chart" }, - { url: "/#BubbleChart", selector: "app-bubble-chart" }, - { url: "/#ScatterChart", selector: "app-scatter-chart" }, - { url: "/#DynamicChart", selector: "app-dynamic-chart" } + { url: '/#LineChart', selector: 'app-line-chart' }, + { url: '/#BarChart', selector: 'app-bar-chart' }, + { url: '/#DoughnutChart', selector: 'app-doughnut-chart' }, + { url: '/#RadarChart', selector: 'app-radar-chart' }, + { url: '/#PieChart', selector: 'app-pie-chart' }, + { url: '/#PolarAreaChart', selector: 'app-polar-area-chart' }, + { url: '/#BubbleChart', selector: 'app-bubble-chart' }, + { url: '/#ScatterChart', selector: 'app-scatter-chart' }, + { url: '/#DynamicChart', selector: 'app-dynamic-chart' }, ]; componentsArray.forEach((component) => { test(`${component.selector}`, async ({ page }) => { await page.goto(component.url); // wait for animations to finish - await expect(page.locator(component.selector) - .locator("canvas")) - .toBeVisible(); + await expect( + page.locator(component.selector).locator('canvas'), + ).toBeVisible(); - return expect(page.locator(component.selector).locator("canvas")).toHaveScreenshot(); + return expect( + page.locator(component.selector).locator('canvas'), + ).toHaveScreenshot(); }); }); diff --git a/apps/ng2-charts-demo/jest.config.ts b/apps/ng2-charts-demo/jest.config.ts index 655c188a..cb73103b 100644 --- a/apps/ng2-charts-demo/jest.config.ts +++ b/apps/ng2-charts-demo/jest.config.ts @@ -1,6 +1,4 @@ -const esModules = [ - 'lodash-es' -].join('|'); +const esModules = ['lodash-es'].join('|'); export default { displayName: 'ng2-charts', preset: '../../jest.preset.js', @@ -24,5 +22,5 @@ export default { 'jest-preset-angular/build/serializers/no-ng-attributes', 'jest-preset-angular/build/serializers/ng-snapshot', 'jest-preset-angular/build/serializers/html-comment', - ] + ], }; diff --git a/apps/ng2-charts-demo/playwright.config.ts b/apps/ng2-charts-demo/playwright.config.ts index dc49a7d7..cae27e80 100644 --- a/apps/ng2-charts-demo/playwright.config.ts +++ b/apps/ng2-charts-demo/playwright.config.ts @@ -1,10 +1,10 @@ -import { defineConfig, devices } from "@playwright/test"; -import { nxE2EPreset } from "@nx/playwright/preset"; +import { defineConfig, devices } from '@playwright/test'; +import { nxE2EPreset } from '@nx/playwright/preset'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -import { workspaceRoot } from "@nx/devkit"; +import { workspaceRoot } from '@nx/devkit'; // For CI, you may want to set BASE_URL to the deployed application. -const baseURL = process.env["BASE_URL"] || "http://localhost:4200"; +const baseURL = process.env['BASE_URL'] || 'http://localhost:4200'; /** * Read environment variables from file. @@ -16,20 +16,22 @@ const baseURL = process.env["BASE_URL"] || "http://localhost:4200"; * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ - ...nxE2EPreset(__filename, { testDir: "./e2e" }), - projects: [{ - name: "chromium", - use: { ...devices["Desktop Chrome"] } - }], + ...nxE2EPreset(__filename, { testDir: './e2e' }), + projects: [ + { + name: 'chromium', + use: { ...devices['Desktop Chrome'] }, + }, + ], webServer: { - command: "npm run serve-static", + command: 'npm run serve-static', url: baseURL, - reuseExistingServer: !process.env.CI + reuseExistingServer: !process.env.CI, }, /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { baseURL, /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: "on-first-retry" - } + trace: 'on-first-retry', + }, }); diff --git a/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.spec.ts b/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.spec.ts index 1c7f8043..499669b8 100644 --- a/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.spec.ts +++ b/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; import { BarChartComponent } from './bar-chart.component'; -import {provideCharts, withDefaultRegisterables} from "ng2-charts"; +import { provideCharts, withDefaultRegisterables } from 'ng2-charts'; describe('BarChartComponent', () => { let component: BarChartComponent; diff --git a/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.ts b/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.ts index b88b15b1..602796f6 100644 --- a/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.ts +++ b/apps/ng2-charts-demo/src/app/bar-chart/bar-chart.component.ts @@ -1,15 +1,21 @@ import { Component, ViewChild } from '@angular/core'; -import { Chart, ChartConfiguration, ChartData, ChartEvent, ChartType } from "chart.js"; +import { + Chart, + ChartConfiguration, + ChartData, + ChartEvent, + ChartType, +} from 'chart.js'; import { BaseChartDirective } from 'ng2-charts'; import DataLabelsPlugin from 'chartjs-plugin-datalabels'; import { MatButton } from '@angular/material/button'; @Component({ - selector: 'app-bar-chart', - templateUrl: './bar-chart.component.html', - styleUrls: ['./bar-chart.component.scss'], - standalone: true, - imports: [MatButton, BaseChartDirective], + selector: 'app-bar-chart', + templateUrl: './bar-chart.component.html', + styleUrls: ['./bar-chart.component.scss'], + standalone: true, + imports: [MatButton, BaseChartDirective], }) export class BarChartComponent { @ViewChild(BaseChartDirective) chart: BaseChartDirective | undefined; diff --git a/apps/ng2-charts-demo/src/app/bubble-chart/bubble-chart.component.html b/apps/ng2-charts-demo/src/app/bubble-chart/bubble-chart.component.html index 22d4badb..8cb74d4c 100644 --- a/apps/ng2-charts-demo/src/app/bubble-chart/bubble-chart.component.html +++ b/apps/ng2-charts-demo/src/app/bubble-chart/bubble-chart.component.html @@ -4,7 +4,8 @@ [data]="bubbleChartData" [options]="bubbleChartOptions" [legend]="true" - [type]="bubbleChartType"> + [type]="bubbleChartType" +>