Skip to content

Commit

Permalink
style: run format
Browse files Browse the repository at this point in the history
  • Loading branch information
nix6839 committed Sep 28, 2023
1 parent 96b4f22 commit 13ce8b9
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 96 deletions.
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,32 @@ command line option.\
💡: Some problems reported by this rule are manually fixable by editor
[suggestions](https://eslint.org/docs/latest/developer-guide/working-with-rules#providing-suggestions).

| | 🔧 | 💡 | Rule | Description |
|| 🔧 | 💡 | Rule | Description |
| :-: | :-: | :-: | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| | | | [expect-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/expect-expect.md) | Enforce assertion to be made in a test body |
| | | | [max-nested-describe](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls |
| | 🔧 | | [missing-playwright-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/missing-playwright-await.md) | Enforce Playwright APIs to be awaited |
| | | | [no-conditional-in-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests |
| | | 💡 | [no-element-handle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-element-handle.md) | Disallow usage of element handles |
| | | | [no-eval](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-eval.md) | Disallow usage of `page.$eval` and `page.$$eval` |
| | | 💡 | [no-focused-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-focused-test.md) | Disallow usage of `.only` annotation |
| | | | [no-force-option](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-force-option.md) | Disallow usage of the `{ force: true }` option |
| | | | [no-nested-step](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nested-step.md) | Disallow nested `test.step()` methods |
| | | | [no-networkidle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-networkidle.md) | Disallow usage of the `networkidle` option |
|| | | [expect-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/expect-expect.md) | Enforce assertion to be made in a test body |
|| | | [max-nested-describe](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls |
|| 🔧 | | [missing-playwright-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/missing-playwright-await.md) | Enforce Playwright APIs to be awaited |
|| | | [no-conditional-in-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests |
|| | 💡 | [no-element-handle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-element-handle.md) | Disallow usage of element handles |
|| | | [no-eval](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-eval.md) | Disallow usage of `page.$eval` and `page.$$eval` |
|| | 💡 | [no-focused-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-focused-test.md) | Disallow usage of `.only` annotation |
|| | | [no-force-option](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-force-option.md) | Disallow usage of the `{ force: true }` option |
|| | | [no-nested-step](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nested-step.md) | Disallow nested `test.step()` methods |
|| | | [no-networkidle](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-networkidle.md) | Disallow usage of the `networkidle` option |
| | | | [no-nth-methods](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-nth-methods.md) | Disallow usage of `first()`, `last()`, and `nth()` methods |
| | | | [no-page-pause](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-page-pause.md) | Disallow using `page.pause` |
|| | | [no-page-pause](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-page-pause.md) | Disallow using `page.pause` |
| | | | [no-raw-locators](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-raw-locators.md) | Disallow using raw locators |
| | 🔧 | | [no-useless-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-await.md) | Disallow unnecessary `await`s for Playwright methods |
|| 🔧 | | [no-useless-await](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-await.md) | Disallow unnecessary `await`s for Playwright methods |
| | | | [no-restricted-matchers](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers |
| | | 💡 | [no-skipped-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-skipped-test.md) | Disallow usage of the `.skip` annotation |
| | 🔧 | | [no-useless-not](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-not.md) | Disallow usage of `not` matchers when a specific matcher exists |
| | | 💡 | [no-wait-for-timeout](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-wait-for-timeout.md) | Disallow usage of `page.waitForTimeout` |
|| | 💡 | [no-skipped-test](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-skipped-test.md) | Disallow usage of the `.skip` annotation |
|| 🔧 | | [no-useless-not](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-useless-not.md) | Disallow usage of `not` matchers when a specific matcher exists |
|| | 💡 | [no-wait-for-timeout](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/no-wait-for-timeout.md) | Disallow usage of `page.waitForTimeout` |
| | | 💡 | [prefer-strict-equal](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` |
| | 🔧 | | [prefer-lowercase-title](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names |
| | 🔧 | | [prefer-to-be](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-be.md) | Suggest using `toBe()` |
| | 🔧 | | [prefer-to-contain](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-contain.md) | Suggest using `toContain()` |
| | 🔧 | | [prefer-to-have-length](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` |
| | 🔧 | | [prefer-web-first-assertions](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-web-first-assertions.md) | Suggest using web first assertions |
|| 🔧 | | [prefer-web-first-assertions](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/prefer-web-first-assertions.md) | Suggest using web first assertions |
| | | | [require-top-level-describe](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `test.describe` block |
| | 🔧 | | [require-soft-assertions](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/require-soft-assertions.md) | Require assertions to use `expect.soft()` |
| | | | [valid-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-expect.md) | Enforce valid `expect()` usage |
|| | | [valid-expect](https://github.com/playwright-community/eslint-plugin-playwright/tree/main/docs/rules/valid-expect.md) | Enforce valid `expect()` usage |
2 changes: 1 addition & 1 deletion docs/rules/no-eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const searchValue = await page.$eval('#search', (el) => el.value);
const divCounts = await page.$$eval(
'div',
(divs, min) => divs.length >= min,
10
10,
);

await page.$eval('#search', (el) => el.value);
Expand Down
4 changes: 2 additions & 2 deletions src/rules/expect-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { getAdditionalAssertFunctionNames } from '../utils/misc';

function isAssertionCall(
node: ESTree.CallExpression,
additionalAssertFunctionNames: string[]
additionalAssertFunctionNames: string[],
) {
return (
isExpectCall(node) ||
additionalAssertFunctionNames.find((name) =>
isIdentifier(node.callee, name)
isIdentifier(node.callee, name),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/missing-playwright-await.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const playwrightTestMatchers = [

function getCallType(
node: ESTree.CallExpression & Rule.NodeParentExtension,
awaitableMatchers: Set<string>
awaitableMatchers: Set<string>,
) {
// test.step
if (
Expand Down
7 changes: 5 additions & 2 deletions src/rules/no-element-handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ export default {
const fixes = [
fixer.replaceTextRange(
getPropertyRange(property),
'locator'
'locator',
),
];

// Remove the await expression if it exists as locators do
// not need to be awaited.
if (node.parent.type === 'AwaitExpression') {
fixes.push(
fixer.removeRange([node.parent.range![0], node.range![0]])
fixer.removeRange([
node.parent.range![0],
node.range![0],
]),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-force-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function isForceOptionEnabled(node: ESTree.CallExpression) {
(property) =>
property.type === 'Property' &&
getStringValue(property.key) === 'force' &&
isBooleanLiteral(property.value, true)
isBooleanLiteral(property.value, true),
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-useless-not.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default {
// As the name implies, this rule only implies if the not modifier is
// part of the matcher chain
const notModifier = expectCall.modifiers.find(
(mod) => getStringValue(mod) === 'not'
(mod) => getStringValue(mod) === 'not',
);
if (!notModifier) return;

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-wait-for-timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default {
fixer.remove(
node.parent && node.parent.type !== 'AwaitExpression'
? node.parent
: node.parent.parent
: node.parent.parent,
),
messageId: 'removeWaitForTimeout',
},
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-lowercase-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type Method = 'test' | 'test.describe';

function isString(
node: ESTree.Expression | ESTree.SpreadElement
node: ESTree.Expression | ESTree.SpreadElement,
): node is ESTree.Literal | ESTree.TemplateLiteral {
return node && (isStringLiteral(node) || node.type === 'TemplateLiteral');
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/prefer-strict-equal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
return replaceAccessorFixer(
fixer,
expectCall.matcher,
'toStrictEqual'
'toStrictEqual',
);
},
messageId: 'suggestReplaceWithStrictEqual',
Expand Down
6 changes: 3 additions & 3 deletions src/rules/prefer-to-be.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function reportPreferToBe(
context: Rule.RuleContext,
expectCall: ParsedExpectCall,
whatToBe: string,
notModifier?: ESTree.Node
notModifier?: ESTree.Node,
) {
context.report({
fix(fixer) {
Expand Down Expand Up @@ -57,15 +57,15 @@ export default {

const notMatchers = ['toBeUndefined', 'toBeDefined'];
const notModifier = expectCall.modifiers.find(
(node) => getStringValue(node) === 'not'
(node) => getStringValue(node) === 'not',
);

if (notModifier && notMatchers.includes(expectCall.matcherName)) {
return reportPreferToBe(
context,
expectCall,
expectCall.matcherName === 'toBeDefined' ? 'Undefined' : 'Defined',
notModifier
notModifier,
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/rules/prefer-to-contain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const matchers = new Set(['toBe', 'toEqual', 'toStrictEqual']);
type FixableIncludesCallExpression = KnownCallExpression;

const isFixableIncludesCallExpression = (
node: ESTree.Node
node: ESTree.Node,
): node is FixableIncludesCallExpression =>
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
Expand Down Expand Up @@ -43,7 +43,7 @@ export default {
}

const notModifier = expectCall.modifiers.find(
(node) => getStringValue(node) === 'not'
(node) => getStringValue(node) === 'not',
);

context.report({
Expand All @@ -65,12 +65,12 @@ export default {
// replace the current matcher with "toContain", adding "not" if needed
fixer.replaceText(
matcher,
addNotModifier ? 'not.toContain' : 'toContain'
addNotModifier ? 'not.toContain' : 'toContain',
),
// replace the matcher argument with the value from the "includes"
fixer.replaceText(
expectCall.args[0],
sourceCode.getText(includesCall.arguments[0])
sourceCode.getText(includesCall.arguments[0]),
),
];

Expand All @@ -80,7 +80,7 @@ export default {
fixer.removeRange([
notModifier.range![0],
notModifier.range![1] + 1,
])
]),
);
}

Expand Down
13 changes: 8 additions & 5 deletions src/rules/prefer-web-first-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default {
// Change the matcher
const { args, matcher } = expectCall;
const notModifier = expectCall.modifiers.find(
(mod) => getStringValue(mod) === 'not'
(mod) => getStringValue(mod) === 'not',
);

const isFalsy =
Expand Down Expand Up @@ -121,12 +121,12 @@ export default {
// Remove the await keyword
fixer.replaceTextRange(
[arg.range![0], arg.argument.range![0]],
''
'',
),
// Remove the old Playwright method and any arguments
fixer.replaceTextRange(
[callee.property.range![0] - 1, methodEnd],
''
'',
),
];

Expand All @@ -151,7 +151,7 @@ export default {

// Add the new matcher arguments if needed
const hasOtherArgs = !!methodArgs.filter(
(arg) => !isBooleanLiteral(arg)
(arg) => !isBooleanLiteral(arg),
).length;

if (methodArgs) {
Expand All @@ -162,7 +162,10 @@ export default {
.join(', ');

fixes.push(
fixer.insertTextAfterRange([range[0], range[1] + 1], stringArgs)
fixer.insertTextAfterRange(
[range[0], range[1] + 1],
stringArgs,
),
);
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function isBooleanLiteral(node: ESTree.Node, value?: boolean) {

export function isPropertyAccessor(
node: ESTree.MemberExpression,
name: string
name: string,
) {
return getStringValue(node.property) === name;
}
Expand Down Expand Up @@ -85,7 +85,7 @@ export function isDescribeCall(node: ESTree.Node): boolean {

export function findParent<T extends ESTree.Node['type']>(
node: NodeWithParent,
type: T
type: T,
): TypedNodeWithParent<T> | undefined {
if (!node.parent) return;

Expand All @@ -103,7 +103,7 @@ export function isTest(node: ESTree.CallExpression, modifiers?: string[]) {
modifiers?.includes(getStringValue(node.callee.property))) &&
node.arguments.length === 2 &&
['ArrowFunctionExpression', 'FunctionExpression'].includes(
node.arguments[1].type
node.arguments[1].type,
)
);
}
Expand All @@ -121,7 +121,7 @@ const expectSubCommands = new Set(['soft', 'poll']);
export type ExpectType = 'poll' | 'soft' | 'standalone';

export function getExpectType(
node: ESTree.CallExpression
node: ESTree.CallExpression,
): ExpectType | undefined {
if (isIdentifier(node.callee, /(^expect|Expect)$/)) {
return 'standalone';
Expand All @@ -142,7 +142,7 @@ export function isExpectCall(node: ESTree.CallExpression) {

export function getMatchers(
node: Rule.Node,
chain: Rule.Node[] = []
chain: Rule.Node[] = [],
): Rule.Node[] {
if (node.parent.type === 'MemberExpression' && node.parent.object === node) {
return getMatchers(node.parent, [
Expand Down
Loading

0 comments on commit 13ce8b9

Please sign in to comment.