fix: add prefer-dom-node-dataset rule (#5107)

This commit is contained in:
LongYinan 2023-11-29 04:43:35 +00:00
parent 923844f302
commit 123f091e5b
No known key found for this signature in database
GPG Key ID: 30B1140CE1C07C99
9 changed files with 13 additions and 22 deletions

View File

@ -207,6 +207,7 @@ const config = {
],
'unicorn/no-unnecessary-await': 'error',
'unicorn/no-useless-fallback-in-spread': 'error',
'unicorn/prefer-dom-node-dataset': 'error',
'sonarjs/no-all-duplicated-branches': 'error',
'sonarjs/no-element-overwrite': 'error',
'sonarjs/no-empty-collection': 'error',

View File

@ -84,8 +84,7 @@ const Settings = () => {
scrollWrapper.current.getBoundingClientRect().left -
parseInt(wrapperComputedStyle.paddingLeft)
: 0;
const appeared =
scrollWrapper.current.getAttribute('data-appeared') === 'true';
const appeared = scrollWrapper.current.dataset.appeared === 'true';
const animationFrameId = requestAnimationFrame(() => {
scrollWrapper.current?.scrollTo({
behavior: appeared ? 'smooth' : 'instant',

View File

@ -9,7 +9,7 @@ previewBlockIdAtom.onMount = set => {
if (target?.tagName === 'IMG') {
const imageBlock = target.closest('affine-image');
if (imageBlock) {
const blockId = imageBlock.getAttribute('data-block-id');
const blockId = imageBlock.dataset.blockId;
if (!blockId) return;
set(blockId);
}

View File

@ -114,9 +114,7 @@ test('clientBorder value should disable by default on window', async ({
test('app theme', async ({ page, electronApp }) => {
const root = page.locator('html');
{
const themeMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const themeMode = await root.evaluate(element => element.dataset.theme);
expect(themeMode).toBe('light');
const theme = await electronApp.evaluate(({ nativeTheme }) => {
@ -131,9 +129,7 @@ test('app theme', async ({ page, electronApp }) => {
await page.getByTestId('appearance-panel-trigger').click();
await page.waitForTimeout(50);
await page.getByTestId('dark-theme-trigger').click();
const themeMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const themeMode = await root.evaluate(element => element.dataset.theme);
expect(themeMode).toBe('dark');
const theme = await electronApp.evaluate(({ nativeTheme }) => {
return nativeTheme.shouldUseDarkColors ? 'dark' : 'light';

View File

@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-dom-node-dataset */
import { test } from '@affine-test/kit/playwright';
import {
changeFilter,
@ -307,7 +308,6 @@ test('select a group of items by clicking "Select All" in group header', async (
const selectedGroupItemTotalCount = await page
.locator('[data-testid="page-list-group-header"]')
.getAttribute('data-group-items-count');
expect(selectedItemCount).toBe(selectedGroupItemTotalCount);
// check the selected count is equal to the one displayed in the floating toolbar

View File

@ -1,3 +1,4 @@
/* eslint-disable unicorn/prefer-dom-node-dataset */
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,

View File

@ -49,15 +49,11 @@ test('Change theme', async ({ page }) => {
const root = page.locator('html');
await page.getByTestId('light-theme-trigger').click();
const lightMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const lightMode = await root.evaluate(element => element.dataset.theme);
expect(lightMode).toBe('light');
await page.getByTestId('dark-theme-trigger').click();
const darkMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const darkMode = await root.evaluate(element => element.dataset.theme);
expect(darkMode).toBe('dark');
});

View File

@ -14,9 +14,7 @@ test('default white', async ({ browser }) => {
await openHomePage(page);
await waitForEditorLoad(page);
const root = page.locator('html');
const themeMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const themeMode = await root.evaluate(element => element.dataset.theme);
expect(themeMode).toBe('light');
await page.screenshot({
path: resolve(testResultDir, 'affine-light-theme.png'),
@ -25,9 +23,7 @@ test('default white', async ({ browser }) => {
await page.getByTestId('appearance-panel-trigger').click();
await page.waitForTimeout(50);
await page.getByTestId('dark-theme-trigger').click();
const darkMode = await root.evaluate(element =>
element.getAttribute('data-theme')
);
const darkMode = await root.evaluate(element => element.dataset.theme);
expect(darkMode).toBe('dark');
await page.screenshot({
path: resolve(testResultDir, 'affine-dark-theme.png'),

View File

@ -48,6 +48,8 @@ export const getPagesCount = async (page: Page) => {
return 0;
}
// locator is not a HTMLElement, so we can't use dataset
// eslint-disable-next-line unicorn/prefer-dom-node-dataset
const count = await locator.getAttribute('data-total-count');
return count ? parseInt(count) : 0;
};