From 7999891e9cf48a27ee053e702667b55344714896 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Thu, 9 Sep 2021 17:05:07 +0200 Subject: [PATCH] fix(types): return `this` rather than the class (#360) --- packages/playwright/src/index.ts | 22 +++++++++++----------- packages/webdriverio/src/index.ts | 28 ++++++++++++++-------------- packages/webdriverjs/src/index.ts | 14 +++++++------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index 64cebaae..5d76097b 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -38,10 +38,10 @@ export default class AxeBuilder { * Selector to include in analysis. * This may be called any number of times. * @param String selector - * @returns AxeBuilder + * @returns this */ - public include(selector: string): AxeBuilder { + public include(selector: string): this { this.includes.push(selector); return this; } @@ -50,10 +50,10 @@ export default class AxeBuilder { * Selector to exclude in analysis. * This may be called any number of times. * @param String selector - * @returns AxeBuilder + * @returns this */ - public exclude(selector: string): AxeBuilder { + public exclude(selector: string): this { this.excludes.push(selector); return this; } @@ -64,7 +64,7 @@ export default class AxeBuilder { * @returns AxeBuilder */ - public options(options: RunOptions): AxeBuilder { + public options(options: RunOptions): this { this.option = options; return this; } @@ -73,10 +73,10 @@ export default class AxeBuilder { * Limit analysis to only the specified rules. * Cannot be used with `AxeBuilder#withTags` * @param String|Array rules - * @returns AxeBuilder + * @returns this */ - public withRules(rules: string | string[]): AxeBuilder { + public withRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; /* istanbul ignore next */ this.option = this.option || {}; @@ -92,10 +92,10 @@ export default class AxeBuilder { * Limit analysis to only specified tags. * Cannot be used with `AxeBuilder#withRules` * @param String|Array tags - * @returns AxeBuilder + * @returns this */ - public withTags(tags: string | string[]): AxeBuilder { + public withTags(tags: string | string[]): this { tags = Array.isArray(tags) ? tags : [tags]; /* istanbul ignore next */ this.option = this.option || {}; @@ -109,10 +109,10 @@ export default class AxeBuilder { /** * Set the list of rules to skip when running an analysis. * @param String|Array rules - * @returns AxeBuilder + * @returns this */ - public disableRules(rules: string | string[]): AxeBuilder { + public disableRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; /* istanbul ignore next */ this.option = this.option || {}; diff --git a/packages/webdriverio/src/index.ts b/packages/webdriverio/src/index.ts index a9111a29..d07add4d 100644 --- a/packages/webdriverio/src/index.ts +++ b/packages/webdriverio/src/index.ts @@ -49,10 +49,10 @@ export default class AxeBuilder { * Disable injecting axe-core into frame(s) matching the * given CSS `selector`. This method may be called any number of times. * @param {String} selector - * @returns {AxeBuilder} + * @returns {this} */ - public disableFrame(selector: string): AxeBuilder { + public disableFrame(selector: string): this { this.disableFrameSelectors.push(cssesc(selector)); return this; } @@ -61,10 +61,10 @@ export default class AxeBuilder { * Selector to include in analysis. * This may be called any number of times. * @param {String} selector - * @returns {AxeBuilder} + * @returns {this} */ - public include(selector: string): AxeBuilder { + public include(selector: string): this { this.includes.push(selector); return this; } @@ -73,10 +73,10 @@ export default class AxeBuilder { * Selector to exclude in analysis. * This may be called any number of times. * @param {String} selector - * @returns {AxeBuilder} + * @returns {this} */ - public exclude(selector: string): AxeBuilder { + public exclude(selector: string): this { this.excludes.push(selector); return this; } @@ -84,10 +84,10 @@ export default class AxeBuilder { /** * Set options to be passed into axe-core * @param {RunOptions} options - * @returns {AxeBuilder} + * @returns {this} */ - public options(options: RunOptions): AxeBuilder { + public options(options: RunOptions): this { this.option = options; return this; } @@ -96,10 +96,10 @@ export default class AxeBuilder { * Limit analysis to only the specified rules. * Cannot be used with `AxeBuilder#withTags` * @param {String|Array} rules - * @returns {AxeBuilder} + * @returns {this} */ - public withRules(rules: string | string[]): AxeBuilder { + public withRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; /* istanbul ignore next */ this.option = this.option || {}; @@ -115,10 +115,10 @@ export default class AxeBuilder { * Limit analysis to only specified tags. * Cannot be used with `AxeBuilder#withRules` * @param {String|Array} tags - * @returns {AxeBuilder} + * @returns {this} */ - public withTags(tags: string | string[]): AxeBuilder { + public withTags(tags: string | string[]): this { tags = Array.isArray(tags) ? tags : [tags]; /* istanbul ignore next */ this.option = this.option || {}; @@ -132,10 +132,10 @@ export default class AxeBuilder { /** * Set the list of rules to skip when running an analysis. * @param {String|Array} rules - * @returns {AxeBuilder} + * @returns {this} */ - public disableRules(rules: string | string[]): AxeBuilder { + public disableRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; /* istanbul ignore next */ this.option = this.option || {}; diff --git a/packages/webdriverjs/src/index.ts b/packages/webdriverjs/src/index.ts index 76c6ae16..6a680f72 100644 --- a/packages/webdriverjs/src/index.ts +++ b/packages/webdriverjs/src/index.ts @@ -41,7 +41,7 @@ class AxeBuilder { * Selector to include in analysis. * This may be called any number of times. */ - public include(selector: string): AxeBuilder { + public include(selector: string): this { this.includes.push(selector); return this; } @@ -50,7 +50,7 @@ class AxeBuilder { * Selector to exclude in analysis. * This may be called any number of times. */ - public exclude(selector: string): AxeBuilder { + public exclude(selector: string): this { this.excludes.push(selector); return this; } @@ -58,7 +58,7 @@ class AxeBuilder { /** * Set options to be passed into axe-core */ - public options(options: RunOptions): AxeBuilder { + public options(options: RunOptions): this { this.option = options; return this; } @@ -67,7 +67,7 @@ class AxeBuilder { * Limit analysis to only the specified rules. * Cannot be used with `AxeBuilder#withTags` */ - public withRules(rules: string | string[]): AxeBuilder { + public withRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; this.option.runOnly = { type: 'rule', @@ -81,7 +81,7 @@ class AxeBuilder { * Limit analysis to only specified tags. * Cannot be used with `AxeBuilder#withRules` */ - public withTags(tags: string | string[]): AxeBuilder { + public withTags(tags: string | string[]): this { tags = Array.isArray(tags) ? tags : [tags]; this.option.runOnly = { type: 'tag', @@ -93,7 +93,7 @@ class AxeBuilder { /** * Set the list of rules to skip when running an analysis. */ - public disableRules(rules: string | string[]): AxeBuilder { + public disableRules(rules: string | string[]): this { rules = Array.isArray(rules) ? rules : [rules]; this.option.rules = {}; for (const rule of rules) { @@ -106,7 +106,7 @@ class AxeBuilder { * Set configuration for `axe-core`. * This value is passed directly to `axe.configure()` */ - public configure(config: Spec): AxeBuilder { + public configure(config: Spec): this { if (typeof config !== 'object') { throw new Error( 'AxeBuilder needs an object to configure. See axe-core configure API.'