From ffb19a97b0a93caf78336026f68d474dd45efb01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bengt=20Wei=C3=9Fe?= Date: Fri, 13 Sep 2024 09:43:01 +0200 Subject: [PATCH] style: stylistic objects --- .prettierrc | 4 --- eslint.config.mjs | 8 ++++- .../config/src/provide-quill-config.ts | 3 +- .../config/src/quill-config.module.ts | 3 +- projects/ngx-quill/karma.conf.js | 11 ++++-- .../src/lib/quill-editor.component.spec.ts | 36 ++++++++++--------- .../src/lib/quill-view.component.spec.ts | 10 +++--- .../ngx-quill/src/lib/quill-view.component.ts | 2 +- projects/ngx-quill/src/lib/quill.service.ts | 7 ++-- 9 files changed, 49 insertions(+), 35 deletions(-) delete mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index b2095be8..00000000 --- a/.prettierrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "semi": false, - "singleQuote": true -} diff --git a/eslint.config.mjs b/eslint.config.mjs index 5892f172..32a8b040 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -65,6 +65,9 @@ export default tseslint.config( multilineDetection: 'brackets' } ], + '@stylistic/object-property-newline': ['error'], + '@stylistic/object-curly-newline': ['error'], + '@stylistic/object-curly-spacing': ['error', 'always'], '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-non-null-assertion': 'off', @@ -131,7 +134,10 @@ export default tseslint.config( multilineDetection: 'brackets' } ], - '@stylistic/comma-dangle': ['error', 'never'] + '@stylistic/comma-dangle': ['error', 'never'], + '@stylistic/object-property-newline': ['error'], + '@stylistic/object-curly-newline': ['error'], + '@stylistic/object-curly-spacing': ['error', 'always'] } }, diff --git a/projects/ngx-quill/config/src/provide-quill-config.ts b/projects/ngx-quill/config/src/provide-quill-config.ts index fd1bc3bc..75385bbf 100644 --- a/projects/ngx-quill/config/src/provide-quill-config.ts +++ b/projects/ngx-quill/config/src/provide-quill-config.ts @@ -11,4 +11,5 @@ import { QUILL_CONFIG_TOKEN, QuillConfig } from './quill-editor.interfaces' * ``` */ export const provideQuillConfig = (config: QuillConfig): EnvironmentProviders => - makeEnvironmentProviders([{ provide: QUILL_CONFIG_TOKEN, useValue: config }]) + makeEnvironmentProviders([{ provide: QUILL_CONFIG_TOKEN, +useValue: config }]) diff --git a/projects/ngx-quill/config/src/quill-config.module.ts b/projects/ngx-quill/config/src/quill-config.module.ts index 07f9d564..d8354ff9 100644 --- a/projects/ngx-quill/config/src/quill-config.module.ts +++ b/projects/ngx-quill/config/src/quill-config.module.ts @@ -13,7 +13,8 @@ export class QuillConfigModule { static forRoot(config: QuillConfig): ModuleWithProviders { return { ngModule: QuillConfigModule, - providers: [{ provide: QUILL_CONFIG_TOKEN, useValue: config }], + providers: [{ provide: QUILL_CONFIG_TOKEN, +useValue: config }], } } } diff --git a/projects/ngx-quill/karma.conf.js b/projects/ngx-quill/karma.conf.js index fa85901e..bb4ccd21 100644 --- a/projects/ngx-quill/karma.conf.js +++ b/projects/ngx-quill/karma.conf.js @@ -22,9 +22,14 @@ module.exports = function (config) { coverageReporter: { dir: require('path').join(__dirname, '../../coverage/ngx-quill'), reporters: [ - { type: 'html', subdir: 'report-html' }, - { type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' }, - { type: 'text-summary', subdir: '.', file: 'text-summary.txt' } + { type: 'html', + subdir: 'report-html' }, + { type: 'lcovonly', + subdir: '.', + file: 'report-lcovonly.txt' }, + { type: 'text-summary', + subdir: '.', + file: 'text-summary.txt' } ], check: { global: { diff --git a/projects/ngx-quill/src/lib/quill-editor.component.spec.ts b/projects/ngx-quill/src/lib/quill-editor.component.spec.ts index bce98133..45471aeb 100644 --- a/projects/ngx-quill/src/lib/quill-editor.component.spec.ts +++ b/projects/ngx-quill/src/lib/quill-editor.component.spec.ts @@ -1,13 +1,13 @@ -import {Component, Renderer2, ViewChild} from '@angular/core' -import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing' -import {defer} from 'rxjs' +import { Component, Renderer2, ViewChild } from '@angular/core' +import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing' +import { defer } from 'rxjs' -import {FormControl, FormsModule, ReactiveFormsModule} from '@angular/forms' +import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms' -import {QuillEditorComponent} from './quill-editor.component' +import { QuillEditorComponent } from './quill-editor.component' import Quill from 'quill' -import {QuillModule} from './quill.module' +import { QuillModule } from './quill.module' window.setTimeout = ((cb) => { cb() @@ -276,7 +276,7 @@ describe('Formats', () => { await fixture.whenStable() await fixture.whenStable() - expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hello\n'}]})) + expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hello\n' }] })) }) it('should update text', async () => { @@ -286,7 +286,7 @@ describe('Formats', () => { fixture.detectChanges() await fixture.whenStable() - expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: '1234\n'}]})) + expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: '1234\n' }] })) }) it('should update model if editor text changes', async () => { @@ -297,7 +297,7 @@ describe('Formats', () => { fixture.detectChanges() await fixture.whenStable() - expect(JSON.stringify(component.title)).toEqual(JSON.stringify({ops: [{insert: '123\n'}]})) + expect(JSON.stringify(component.title)).toEqual(JSON.stringify({ ops: [{ insert: '123\n' }] })) }) }) @@ -373,13 +373,13 @@ unordered`) const incomponent = sanfixture.componentInstance expect(JSON.stringify(incomponent.editor.getContents())) - .toEqual(JSON.stringify({ops: [{insert: 'Hallo ' }, {insert: {image: 'wroooong.jpg'}}, {insert: '\n'}]})) + .toEqual(JSON.stringify({ ops: [{ insert: 'Hallo ' }, { insert: { image: 'wroooong.jpg' } }, { insert: '\n' }] })) incomponent.title = '

' sanfixture.detectChanges() await sanfixture.whenStable() - expect(JSON.stringify(incomponent.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: {image: 'xxxx'}}, {insert: '\n'}]})) + expect(JSON.stringify(incomponent.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: { image: 'xxxx' } }, { insert: '\n' }] })) }) }) @@ -495,7 +495,7 @@ unordered`) }) it('should set json string', async () => { - expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo\n'}]})) + expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo\n' }] })) }) it('should update json string', async () => { @@ -504,7 +504,7 @@ unordered`) }]) fixture.detectChanges() await fixture.whenStable() - expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]})) + expect(JSON.stringify(component.editor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] })) }) it('should update model if editor changes', async () => { @@ -514,7 +514,7 @@ unordered`) fixture.detectChanges() await fixture.whenStable() - expect(component.title).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]})) + expect(component.title).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] })) }) it('should set as text if invalid JSON', async () => { @@ -1343,10 +1343,14 @@ describe('QuillEditor - base config', () => { fixture.detectChanges() expect(JSON.stringify(fixture.componentInstance.title)) - .toEqual(JSON.stringify({ ops: [{ attributes: { bold: true }, insert: 'content'}, {insert: '\n'}] })) + .toEqual(JSON.stringify({ ops: [{ attributes: { bold: true }, +insert: 'content' }, { insert: '\n' }] })) expect(editor.root.dataset.placeholder).toEqual('placeholder') expect(registerSpy).toHaveBeenCalledWith( - jasmine.objectContaining({attrName: 'size', keyName: 'font-size', scope: 5, whitelist: ['14']}), true, true + jasmine.objectContaining({ attrName: 'size', +keyName: 'font-size', +scope: 5, +whitelist: ['14'] }), true, true ) expect(fixture.componentInstance.editorComponent.quillEditor['options'].modules.toolbar) diff --git a/projects/ngx-quill/src/lib/quill-view.component.spec.ts b/projects/ngx-quill/src/lib/quill-view.component.spec.ts index 2d81a3f0..616084cd 100644 --- a/projects/ngx-quill/src/lib/quill-view.component.spec.ts +++ b/projects/ngx-quill/src/lib/quill-view.component.spec.ts @@ -88,7 +88,7 @@ describe('Formats', () => { const component = fixture.componentInstance await fixture.whenStable() - expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hello\n'}]})) + expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hello\n' }] })) }) it('should update object content', async () => { @@ -98,7 +98,7 @@ describe('Formats', () => { fixture.detectChanges() await fixture.whenStable() - expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: '1234\n'}]})) + expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: '1234\n' }] })) }) }) @@ -220,7 +220,7 @@ describe('Formats', () => { await fixture.whenStable() await fixture.whenStable() - expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo\n'}]})) + expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo\n' }] })) }) it('should update json string', async () => { @@ -233,7 +233,7 @@ describe('Formats', () => { fixture.detectChanges() await fixture.whenStable() - expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ops: [{insert: 'Hallo 123\n'}]})) + expect(JSON.stringify(component.view!.quillEditor.getContents())).toEqual(JSON.stringify({ ops: [{ insert: 'Hallo 123\n' }] })) }) }) }) @@ -246,7 +246,7 @@ describe('Advanced QuillViewComponent', () => { ` }) class AdvancedComponent { - @ViewChild(QuillViewComponent, {static: true}) view: QuillViewComponent | undefined + @ViewChild(QuillViewComponent, { static: true }) view: QuillViewComponent | undefined content = '

Hallo

' quillEditor: any diff --git a/projects/ngx-quill/src/lib/quill-view.component.ts b/projects/ngx-quill/src/lib/quill-view.component.ts index efc9b2a1..5cd1f28e 100644 --- a/projects/ngx-quill/src/lib/quill-view.component.ts +++ b/projects/ngx-quill/src/lib/quill-view.component.ts @@ -87,7 +87,7 @@ export class QuillViewComponent implements AfterViewInit, OnChanges, OnDestroy { if (sanitize) { value = this.domSanitizer.sanitize(SecurityContext.HTML, value) } - content = quillEditor.clipboard.convert({html: value}) + content = quillEditor.clipboard.convert({ html: value }) } else if (format === 'json') { try { content = JSON.parse(value) diff --git a/projects/ngx-quill/src/lib/quill.service.ts b/projects/ngx-quill/src/lib/quill.service.ts index 1483fba6..faf95f61 100644 --- a/projects/ngx-quill/src/lib/quill.service.ts +++ b/projects/ngx-quill/src/lib/quill.service.ts @@ -1,13 +1,13 @@ import { DOCUMENT } from '@angular/common' -import { Injectable, Inject, Injector, Optional } from '@angular/core' +import { Inject, Injectable, Injector, Optional } from '@angular/core' import { defer, firstValueFrom, isObservable, Observable } from 'rxjs' import { shareReplay } from 'rxjs/operators' import { + CustomModule, defaultModules, QUILL_CONFIG_TOKEN, QuillConfig, - CustomModule, } from 'ngx-quill/config' @Injectable({ @@ -59,7 +59,8 @@ export class QuillService { this.config.customModules, this.config.suppressGlobalRegisterWarning ) - }).pipe(shareReplay({ bufferSize: 1, refCount: true })) + }).pipe(shareReplay({ bufferSize: 1, +refCount: true })) constructor( injector: Injector,