Skip to content

Commit

Permalink
feat: ✨ add missing imports rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Apr 7, 2024
1 parent d51c9f3 commit f896437
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 10 deletions.
82 changes: 82 additions & 0 deletions src/__snapshots__/factory.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1921,12 +1921,18 @@ exports[`jimmyDotCodes > should create configuration w/ jest & react & testing l
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -10041,6 +10047,16 @@ If your function does not access \`this\`, you can annotate it with \`this: void
"jest-dom/prefer-to-have-value": "error",
},
},
{
"files": [
"**/e2e/**/*.spec.?([cm])[jt]s?(x)",
"**/e2e/**/*.test.?([cm])[jt]s?(x)",
],
"name": "jimmy.codes/jest/disabled",
"rules": {
"jest/require-hook": "off",
},
},
{
"files": [
"**/__tests__/**/*.?([cm])[jt]s?(x)",
Expand Down Expand Up @@ -13416,12 +13432,18 @@ exports[`jimmyDotCodes > should create configuration w/ jest 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -15308,6 +15330,16 @@ If your function does not access \`this\`, you can annotate it with \`this: void
"jest-dom/prefer-to-have-value": "error",
},
},
{
"files": [
"**/e2e/**/*.spec.?([cm])[jt]s?(x)",
"**/e2e/**/*.test.?([cm])[jt]s?(x)",
],
"name": "jimmy.codes/jest/disabled",
"rules": {
"jest/require-hook": "off",
},
},
{
"name": "jimmy.codes/disabled",
"rules": {
Expand Down Expand Up @@ -17451,12 +17483,18 @@ exports[`jimmyDotCodes > should create configuration w/ react 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -25833,12 +25871,18 @@ exports[`jimmyDotCodes > should create configuration w/ typescript 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -49226,12 +49270,18 @@ exports[`jimmyDotCodes > should create configuration w/ vitest & react & testing
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -57346,6 +57396,16 @@ If your function does not access \`this\`, you can annotate it with \`this: void
"jest-dom/prefer-to-have-value": "error",
},
},
{
"files": [
"**/e2e/**/*.spec.?([cm])[jt]s?(x)",
"**/e2e/**/*.test.?([cm])[jt]s?(x)",
],
"name": "jimmy.codes/vitest/disabled",
"rules": {
"jest/require-hook": "off",
},
},
{
"files": [
"**/__tests__/**/*.?([cm])[jt]s?(x)",
Expand Down Expand Up @@ -60721,12 +60781,18 @@ exports[`jimmyDotCodes > should create configuration w/ vitest 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down Expand Up @@ -62613,6 +62679,16 @@ If your function does not access \`this\`, you can annotate it with \`this: void
"jest-dom/prefer-to-have-value": "error",
},
},
{
"files": [
"**/e2e/**/*.spec.?([cm])[jt]s?(x)",
"**/e2e/**/*.test.?([cm])[jt]s?(x)",
],
"name": "jimmy.codes/vitest/disabled",
"rules": {
"jest/require-hook": "off",
},
},
{
"name": "jimmy.codes/disabled",
"rules": {
Expand Down Expand Up @@ -65053,12 +65129,18 @@ exports[`jimmyDotCodes > should create default configuration 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down
6 changes: 6 additions & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1921,12 +1921,18 @@ exports[`should create default configuration 1`] = `
"rules": {
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
Expand Down
11 changes: 3 additions & 8 deletions src/configs/imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import importX from "eslint-plugin-import-x";
import nodeImport from "eslint-plugin-node-import";
import simpleImportSort from "eslint-plugin-simple-import-sort";

import { importsRules } from "../rules/imports";

const typescriptImports = {
name: "jimmy.codes/imports/typescript",
settings: {
Expand All @@ -27,14 +29,7 @@ const importsConfig = ({ typescript = false }: ImportsConfigOptions = {}) => {
"simple-import-sort": simpleImportSort,
"node-import": nodeImport,
},
rules: {
...importX.configs.recommended.rules,
// ! can't get this rule to work
"import-x/namespace": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"node-import/prefer-node-protocol": "error",
},
rules: importsRules,
},
...(typescript ? [typescriptImports] : []),
];
Expand Down
9 changes: 8 additions & 1 deletion src/configs/jest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jest from "eslint-plugin-jest";
import * as jestDom from "eslint-plugin-jest-dom";

import { GLOB_TESTS } from "../constants";
import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { jestRules } from "../rules/jest";
import testingLibraryConfig from "./testing-library";

Expand All @@ -26,6 +26,13 @@ const jestConfig = ({
files: GLOB_TESTS,
...jestDom.configs["flat/recommended"],
},
{
name: "jimmy.codes/jest/disabled",
files: GLOB_E2E,
rules: {
"jest/require-hook": "off",
},
},
...(testingLibrary && react ? testingLibraryConfig() : []),
];
};
Expand Down
9 changes: 8 additions & 1 deletion src/configs/vitest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import jest from "eslint-plugin-jest";
import * as jestDom from "eslint-plugin-jest-dom";

import { GLOB_TESTS } from "../constants";
import { GLOB_E2E, GLOB_TESTS } from "../constants";
import { jestRules } from "../rules/jest";
import testingLibraryConfig from "./testing-library";

Expand Down Expand Up @@ -29,6 +29,13 @@ const vitestConfig = ({
files: GLOB_TESTS,
...jestDom.configs["flat/recommended"],
},
{
name: "jimmy.codes/vitest/disabled",
files: GLOB_E2E,
rules: {
"jest/require-hook": "off",
},
},
...(testingLibrary && react ? testingLibraryConfig() : []),
];
};
Expand Down
23 changes: 23 additions & 0 deletions src/rules/__snapshots__/imports.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`should create imports rules 1`] = `
{
"import-x/default": "error",
"import-x/export": "error",
"import-x/first": "error",
"import-x/named": "error",
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/no-absolute-path": "error",
"import-x/no-duplicates": "warn",
"import-x/no-empty-named-blocks": "error",
"import-x/no-named-as-default": "warn",
"import-x/no-named-as-default-member": "warn",
"import-x/no-self-import": "error",
"import-x/no-unresolved": "error",
"import-x/no-useless-path-segments": "error",
"node-import/prefer-node-protocol": "error",
"simple-import-sort/exports": "error",
"simple-import-sort/imports": "error",
}
`;
5 changes: 5 additions & 0 deletions src/rules/imports.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { importsRules } from "./imports";

test("should create imports rules", () => {
expect(importsRules).toMatchSnapshot();
});
17 changes: 17 additions & 0 deletions src/rules/imports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { type Linter } from "eslint";
import importX from "eslint-plugin-import-x";

export const importsRules = {
...importX.configs.recommended.rules,
// ! can't get this rule to work
"import-x/namespace": "off",
"import-x/newline-after-import": "error",
"import-x/first": "error",
"import-x/no-absolute-path": "error",
"import-x/no-useless-path-segments": "error",
"import-x/no-empty-named-blocks": "error",
"import-x/no-self-import": "error",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"node-import/prefer-node-protocol": "error",
} satisfies Linter.RulesRecord;

0 comments on commit f896437

Please sign in to comment.