Skip to content

Commit

Permalink
chore: Import sort plugin (#37)
Browse files Browse the repository at this point in the history
* chore: Import sort plugin

* chore: Replace import sorting pattern for external packages to include everything started optionally with @, but @Cloudscape

* chore: Raise eslint sorting rule to error

* chore: Small eslint rule adjustment
  • Loading branch information
georgylobko authored Jul 24, 2024
1 parent 65c7642 commit 7b02ed3
Show file tree
Hide file tree
Showing 44 changed files with 209 additions and 23 deletions.
31 changes: 27 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"jsx": true
}
},
"plugins": ["unicorn", "react-hooks", "no-unsanitized", "header", "import"],
"plugins": ["unicorn", "react-hooks", "no-unsanitized", "header", "import", "simple-import-sort"],
"rules": {
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/consistent-type-definitions": ["error", "interface"],
Expand Down Expand Up @@ -69,14 +69,13 @@
]
}
],
"sort-imports": ["error", { "ignoreDeclarationSort": true }],
"import/order": ["error", { "alphabetize": { "order": "asc" } }],
"import/no-useless-path-segments": [
"warn",
{
"noUselessIndex": true
}
]
],
"simple-import-sort/imports": "error"
},
"settings": {
"react": {
Expand All @@ -98,6 +97,30 @@
"env": {
"jest": true
}
},
{
"files": ["src/**", "pages/**", "test/**", "scripts/**"],
"rules": {
"simple-import-sort/imports": [
"error",
{
"groups": [
// External packages come first.
["^react", "^(?!@cloudscape)@?\\w"],
// Cloudscape packages.
["^@cloudscape"],
// Things that start with a letter (or digit or underscore), or `~` followed by a letter.
["^~\\w"],
// Anything not matched in another group.
["^"],
// Styles come last.
[
"^.+\\.?(css)$","^.+\\.?(css.js)$", "^.+\\.?(scss)$", "^.+\\.?(selectors.js)$"
]
]
}
]
}
}
]
}
118 changes: 118 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 @@ -100,6 +100,7 @@
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-unicorn": "^45.0.2",
"eslint-plugin-simple-import-sort": "^12.1.1",
"execa": "^6.1.0",
"globby": "^13.1.3",
"husky": "^8.0.3",
Expand Down
1 change: 1 addition & 0 deletions pages/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { HashRouter, Link, Route, Routes, useLocation } from "react-router-dom";

import { pages } from "../pages";
import Page from "./page";

Expand Down
6 changes: 4 additions & 2 deletions pages/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { SpaceBetween, Toggle } from "@cloudscape-design/components";
import { Density, Mode, applyDensity, applyMode } from "@cloudscape-design/global-styles";
import { Suspense } from "react";
import { useEffect, useState } from "react";

import { SpaceBetween, Toggle } from "@cloudscape-design/components";
import { applyDensity, applyMode, Density, Mode } from "@cloudscape-design/global-styles";

import { pagesMap } from "../pages";
import PageLayout from "./page-layout";

Expand Down
1 change: 1 addition & 0 deletions pages/code-view/with-actions-button.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Button, SpaceBetween } from "@cloudscape-design/components";

import { CodeView } from "../../lib/components";
import { ScreenshotArea } from "../screenshot-area";
export default function CodeViewPage() {
Expand Down
1 change: 1 addition & 0 deletions pages/code-view/with-all-features.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Button } from "@cloudscape-design/components";

import { CodeView } from "../../lib/components";
import javascriptHighlight from "../../lib/components/code-view/highlight/javascript";
import { ScreenshotArea } from "../screenshot-area";
Expand Down
2 changes: 1 addition & 1 deletion pages/code-view/with-line-numbers.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { SpaceBetween } from "@cloudscape-design/components";
import { CodeView } from "../../lib/components";

import { CodeView } from "../../lib/components";
import { ScreenshotArea } from "../screenshot-area";
export default function CodeViewPage() {
return (
Expand Down
5 changes: 3 additions & 2 deletions pages/code-view/with-syntax-highlighting.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { SpaceBetween } from "@cloudscape-design/components";

import { CodeView } from "../../lib/components";
import cssHighlight from "../../lib/components/code-view/highlight/css";
import htmlHighlight from "../../lib/components/code-view/highlight/html";
import javaHighlight from "../../lib/components/code-view/highlight/java";
import javascriptHighlight from "../../lib/components/code-view/highlight/javascript";
Expand All @@ -15,8 +15,9 @@ import shHighlight from "../../lib/components/code-view/highlight/sh";
import typescriptHighlight from "../../lib/components/code-view/highlight/typescript";
import xmlHighlight from "../../lib/components/code-view/highlight/xml";
import yamlHighlight from "../../lib/components/code-view/highlight/yaml";

import { ScreenshotArea } from "../screenshot-area";

import cssHighlight from "../../lib/components/code-view/highlight/css";
export default function CodeViewPage() {
return (
<ScreenshotArea>
Expand Down
3 changes: 2 additions & 1 deletion pages/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
import { StrictMode } from "react";
import ReactDOM from "react-dom/client";
import "@cloudscape-design/global-styles/index.css";

import App from "./app";

import "@cloudscape-design/global-styles/index.css";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<StrictMode>
<App />
Expand Down
1 change: 1 addition & 0 deletions scripts/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import path from "node:path";

import { documentComponents, documentTestUtils } from "@cloudscape-design/documenter";

import { dashCase, listPublicDirs, writeSourceFile } from "./utils.js";

const publicDirs = listPublicDirs("src");
Expand Down
1 change: 1 addition & 0 deletions scripts/package-json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import fs from "node:fs";

import { writeJSON } from "./utils.js";

const pkg = JSON.parse(fs.readFileSync("package.json", "utf-8"));
Expand Down
6 changes: 4 additions & 2 deletions scripts/test-utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { execaSync } from "execa";
import { globbySync } from "globby";
import fs from "node:fs";
import path from "node:path";

import { default as convertToSelectorUtil } from "@cloudscape-design/test-utils-converter";
import { execaSync } from "execa";
import { globbySync } from "globby";

import { pascalCase, writeSourceFile } from "./utils.js";

const components = globbySync(["src/test-utils/dom/**/index.ts", "!src/test-utils/dom/index.ts"]).map((fileName) =>
Expand Down
2 changes: 1 addition & 1 deletion scripts/themeable-source.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { globbySync } from "globby";
import fs from "node:fs";
import path from "node:path";
import process from "node:process";
import { globbySync } from "globby";
const cwd = process.cwd();

const targetDir = path.join(cwd, "./lib/components-themeable/internal");
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import lodash from "lodash";
import fs from "node:fs";
import path from "node:path";
import lodash from "lodash";

export function pascalCase(text) {
return capitalize(lodash.camelCase(text));
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/base-props-support.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { render } from "@testing-library/react";
import { ReactElement } from "react";
import { render } from "@testing-library/react";
import { describe, expect, test } from "vitest";

import * as components from "../../lib/components";
import { defaultProps } from "./default-props";

Expand Down
1 change: 1 addition & 0 deletions src/__tests__/documenter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { expect, test } from "vitest";

// @ts-expect-error no types here
import apiDocs from "../../lib/components/internal/api-docs/components";

Expand Down
Loading

0 comments on commit 7b02ed3

Please sign in to comment.