Skip to content

Commit

Permalink
style: add eslint-plugin-simple-import-sort
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Aug 26, 2024
1 parent 96de156 commit 9b002ae
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 35 deletions.
5 changes: 2 additions & 3 deletions __tests__/dom-to-react.test.tsx
Original file line number Diff line number Diff line change
@@ -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([
Expand Down
6 changes: 3 additions & 3 deletions __tests__/esm/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/esm/utilities.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions __tests__/utilities.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
19 changes: 12 additions & 7 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -31,6 +33,7 @@ export default [

plugins: {
'@typescript-eslint': typescriptEslint,
'simple-import-sort': simpleImportSort,
prettier,
},

Expand All @@ -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',
},
},

Expand Down
6 changes: 3 additions & 3 deletions esm/index.mjs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 3 additions & 3 deletions esm/utilities.mjs
Original file line number Diff line number Diff line change
@@ -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';
18 changes: 18 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/attributes-to-props.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
11 changes: 5 additions & 6 deletions src/dom-to-react.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/utilities.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down

0 comments on commit 9b002ae

Please sign in to comment.