From 9b002aec287dce0964f84964a50c99dcdcef3591 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 26 Aug 2024 00:43:57 -0400 Subject: [PATCH] style: add `eslint-plugin-simple-import-sort` --- __tests__/dom-to-react.test.tsx | 5 ++--- __tests__/esm/index.test.mjs | 6 +++--- __tests__/esm/utilities.test.mjs | 6 +++--- __tests__/helpers/index.ts | 2 +- __tests__/utilities.test.ts | 8 ++++---- eslint.config.mjs | 19 ++++++++++++------- esm/index.mjs | 6 +++--- esm/utilities.mjs | 6 +++--- package-lock.json | 18 ++++++++++++++++++ package.json | 1 + src/attributes-to-props.ts | 3 ++- src/dom-to-react.ts | 11 +++++------ src/utilities.ts | 2 +- 13 files changed, 58 insertions(+), 35 deletions(-) diff --git a/__tests__/dom-to-react.test.tsx b/__tests__/dom-to-react.test.tsx index 302cb274..496f3464 100644 --- a/__tests__/dom-to-react.test.tsx +++ b/__tests__/dom-to-react.test.tsx @@ -1,11 +1,10 @@ import htmlToDOM from 'html-dom-parser'; +import { type DOMNode, Element, type HTMLReactParserOptions } from '../src'; import domToReact from '../src/dom-to-react'; import * as utilities from '../src/utilities'; -import { Element, type DOMNode, type HTMLReactParserOptions } from '../src'; - -import { render } from './helpers'; import { html, svg } from './data'; +import { render } from './helpers'; describe('domToReact', () => { it.each([ diff --git a/__tests__/esm/index.test.mjs b/__tests__/esm/index.test.mjs index 01eb71ee..21fa5156 100644 --- a/__tests__/esm/index.test.mjs +++ b/__tests__/esm/index.test.mjs @@ -4,13 +4,13 @@ import assert from 'assert'; import { isValidElement } from 'react'; import parse, { + attributesToProps, Comment, + domToReact, Element, + htmlToDOM, ProcessingInstruction, Text, - attributesToProps, - domToReact, - htmlToDOM, } from '../../esm/index.mjs'; describe('index', () => { diff --git a/__tests__/esm/utilities.test.mjs b/__tests__/esm/utilities.test.mjs index bf983c82..32b5dcf8 100644 --- a/__tests__/esm/utilities.test.mjs +++ b/__tests__/esm/utilities.test.mjs @@ -3,12 +3,12 @@ import { describe, it } from 'node:test'; import assert from 'assert'; import { + canTextBeChildOfNode, + ELEMENTS_WITH_NO_TEXT_CHILDREN, isCustomComponent, - setStyleProp, PRESERVE_CUSTOM_ATTRIBUTES, - ELEMENTS_WITH_NO_TEXT_CHILDREN, - canTextBeChildOfNode, returnFirstArg, + setStyleProp, } from '../../esm/utilities.mjs'; describe('utilities', () => { diff --git a/__tests__/helpers/index.ts b/__tests__/helpers/index.ts index 7bfada43..bcdf19f3 100644 --- a/__tests__/helpers/index.ts +++ b/__tests__/helpers/index.ts @@ -1,5 +1,5 @@ -import { renderToStaticMarkup } from 'react-dom/server'; import type { ReactElement } from 'react'; +import { renderToStaticMarkup } from 'react-dom/server'; /** * Renders a React element to static HTML markup. diff --git a/__tests__/utilities.test.ts b/__tests__/utilities.test.ts index 9ecd1bd6..79ae3c4d 100644 --- a/__tests__/utilities.test.ts +++ b/__tests__/utilities.test.ts @@ -1,14 +1,14 @@ -import * as React from 'react'; import type { Element } from 'html-dom-parser'; +import * as React from 'react'; +import type { Props } from '../src/attributes-to-props'; import { - PRESERVE_CUSTOM_ATTRIBUTES, + canTextBeChildOfNode, ELEMENTS_WITH_NO_TEXT_CHILDREN, isCustomComponent, + PRESERVE_CUSTOM_ATTRIBUTES, setStyleProp, - canTextBeChildOfNode, } from '../src/utilities'; -import type { Props } from '../src/attributes-to-props'; describe('isCustomComponent', () => { it('returns true if the tag contains a hyphen and is not in the whitelist', () => { diff --git a/eslint.config.mjs b/eslint.config.mjs index 1295ee55..d10120bf 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -1,12 +1,14 @@ -import typescriptEslint from '@typescript-eslint/eslint-plugin'; -import prettier from 'eslint-plugin-prettier'; -import globals from 'globals'; -import tsParser from '@typescript-eslint/parser'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; -import js from '@eslint/js'; -import { FlatCompat } from '@eslint/eslintrc'; + import { includeIgnoreFile } from '@eslint/compat'; +import { FlatCompat } from '@eslint/eslintrc'; +import js from '@eslint/js'; +import typescriptEslint from '@typescript-eslint/eslint-plugin'; +import tsParser from '@typescript-eslint/parser'; +import prettier from 'eslint-plugin-prettier'; +import simpleImportSort from 'eslint-plugin-simple-import-sort'; +import globals from 'globals'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -31,6 +33,7 @@ export default [ plugins: { '@typescript-eslint': typescriptEslint, + 'simple-import-sort': simpleImportSort, prettier, }, @@ -44,11 +47,13 @@ export default [ }, rules: { - '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-var-requires': 'off', 'no-console': 'error', 'no-debugger': 'error', 'prettier/prettier': 'error', + 'simple-import-sort/exports': 'error', + 'simple-import-sort/imports': 'error', }, }, diff --git a/esm/index.mjs b/esm/index.mjs index 572a9d98..e6372d80 100644 --- a/esm/index.mjs +++ b/esm/index.mjs @@ -1,13 +1,13 @@ import HTMLReactParser from '../lib/index.js'; export { + attributesToProps, Comment, + domToReact, Element, + htmlToDOM, ProcessingInstruction, Text, - attributesToProps, - domToReact, - htmlToDOM, } from '../lib/index.js'; export default HTMLReactParser.default || HTMLReactParser; diff --git a/esm/utilities.mjs b/esm/utilities.mjs index 281cb293..9ce1be32 100644 --- a/esm/utilities.mjs +++ b/esm/utilities.mjs @@ -1,8 +1,8 @@ export { + canTextBeChildOfNode, + ELEMENTS_WITH_NO_TEXT_CHILDREN, isCustomComponent, - setStyleProp, PRESERVE_CUSTOM_ATTRIBUTES, - ELEMENTS_WITH_NO_TEXT_CHILDREN, - canTextBeChildOfNode, returnFirstArg, + setStyleProp, } from '../lib/utilities.js'; diff --git a/package-lock.json b/package-lock.json index 5dcbb308..225deef9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,6 +34,7 @@ "benchmark": "2.1.4", "eslint": "9.9.1", "eslint-plugin-prettier": "5.2.1", + "eslint-plugin-simple-import-sort": "12.1.1", "globals": "15.9.0", "husky": "9.1.5", "jest": "29.7.0", @@ -4793,6 +4794,16 @@ } } }, + "node_modules/eslint-plugin-simple-import-sort": { + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-12.1.1.tgz", + "integrity": "sha512-6nuzu4xwQtE3332Uz0to+TxDQYRLTKRESSc2hefVT48Zc8JthmN23Gx9lnYhu0FtkRSL1oxny3kJ2aveVhmOVA==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "eslint": ">=5.0.0" + } + }, "node_modules/eslint-scope": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", @@ -13470,6 +13481,13 @@ "synckit": "^0.9.1" } }, + "eslint-plugin-simple-import-sort": { + "version": "12.1.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-simple-import-sort/-/eslint-plugin-simple-import-sort-12.1.1.tgz", + "integrity": "sha512-6nuzu4xwQtE3332Uz0to+TxDQYRLTKRESSc2hefVT48Zc8JthmN23Gx9lnYhu0FtkRSL1oxny3kJ2aveVhmOVA==", + "dev": true, + "requires": {} + }, "eslint-scope": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", diff --git a/package.json b/package.json index c6ac5107..ca221075 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,7 @@ "benchmark": "2.1.4", "eslint": "9.9.1", "eslint-plugin-prettier": "5.2.1", + "eslint-plugin-simple-import-sort": "12.1.1", "globals": "15.9.0", "husky": "9.1.5", "jest": "29.7.0", diff --git a/src/attributes-to-props.ts b/src/attributes-to-props.ts index db403e13..fcba5359 100644 --- a/src/attributes-to-props.ts +++ b/src/attributes-to-props.ts @@ -1,10 +1,11 @@ import { BOOLEAN, - OVERLOADED_BOOLEAN, getPropertyInfo, isCustomAttribute, + OVERLOADED_BOOLEAN, possibleStandardNames, } from 'react-property'; + import { PRESERVE_CUSTOM_ATTRIBUTES, setStyleProp } from './utilities'; // https://react.dev/learn/sharing-state-between-components#controlled-and-uncontrolled-components diff --git a/src/dom-to-react.ts b/src/dom-to-react.ts index 725e9342..926880e3 100644 --- a/src/dom-to-react.ts +++ b/src/dom-to-react.ts @@ -1,19 +1,18 @@ -import { cloneElement, createElement, isValidElement } from 'react'; +import type { DOMNode, Element, Text } from 'html-dom-parser'; import type { JSX } from 'react'; -import type { Element, DOMNode, Text } from 'html-dom-parser'; +import { cloneElement, createElement, isValidElement } from 'react'; -import attributesToProps from './attributes-to-props'; import type { Props } from './attributes-to-props'; +import attributesToProps from './attributes-to-props'; +import type { HTMLReactParserOptions } from './types'; import { - PRESERVE_CUSTOM_ATTRIBUTES, canTextBeChildOfNode, isCustomComponent, + PRESERVE_CUSTOM_ATTRIBUTES, returnFirstArg, setStyleProp, } from './utilities'; -import type { HTMLReactParserOptions } from './types'; - const React = { cloneElement, createElement, diff --git a/src/utilities.ts b/src/utilities.ts index d6537f47..0698b39f 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -1,6 +1,6 @@ +import type { Element } from 'html-dom-parser'; import { version } from 'react'; import StyleToJS from 'style-to-js'; -import type { Element } from 'html-dom-parser'; import type { Props } from './attributes-to-props';