Skip to content

Commit

Permalink
Refactor imports and update ESLint rules (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonyfaris authored Oct 23, 2023
1 parent 97e4b8d commit f71ecd7
Show file tree
Hide file tree
Showing 82 changed files with 228 additions and 402 deletions.
10 changes: 10 additions & 0 deletions .changeset/ninety-turtles-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@modular-rocks/traverse-files': patch
'@modular-rocks/workspace-node': patch
'@modular-rocks/slimfast-node': patch
'eslint-config-custom': patch
'@modular-rocks/workspace': patch
'@modular-rocks/slimfast': patch
---

Internal: Refactored imports across all packages and modified eslint rules for better code consistency.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ jobs:

- name: Linting
run: pnpm lint

- name: Format
run: pnpm check:format
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"trailingComma": "es5",
"singleQuote": true
"singleQuote": true,
"endOfLine": "lf"
}
43 changes: 29 additions & 14 deletions config/eslint-config/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
/**
* @type {import("eslint").Linter.Config}
*/
module.exports = {
env: {
commonjs: true,
es2021: true,
node: true,
},
extends: [
'airbnb-base',
'airbnb-typescript/base',
'plugin:prettier/recommended',
],
extends: ['airbnb-base', 'airbnb-typescript/base', 'prettier'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['@typescript-eslint', 'prettier'],
plugins: ['@typescript-eslint', 'unused-imports'],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'prettier/prettier': [
'error',
{
usePrettierrc: true,
endOfLine: 'auto',
},
],
'import/extensions': [
'error',
'ignorePackages',
Expand All @@ -42,10 +34,33 @@ module.exports = {
'no-await-in-loop': 'off',
'no-async-promise-executor': 'off',
'@typescript-eslint/no-useless-constructor': 'off',
'import/no-cycle': 'off',
'import/no-extraneous-dependencies': 'off', // needed for the monorepo
'import/prefer-default-export': 'off',
'@typescript-eslint/no-floating-promises': 'error',
'arrow-body-style': 'off',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-exports': 'error',
'import/order': [
'error',
{
groups: [
['builtin', 'internal'],
'external',
['index', 'parent', 'sibling'],
'object',
'type',
],
distinctGroup: true,
'newlines-between': 'always',
alphabetize: {
order: 'asc',
orderImportKind: 'asc',
caseInsensitive: true,
},
warnOnUnassignedImports: true,
},
],
'unused-imports/no-unused-imports': 'error',
},

ignorePatterns: ['.eslintrc.cjs', 'dist', 'turbo', 'coverage'],
Expand Down
2 changes: 1 addition & 1 deletion config/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"eslint-config-airbnb-typescript": "17.1.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-import": "2.28.1",
"eslint-plugin-prettier": "5.0.0"
"eslint-plugin-unused-imports": "3.0.0"
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"coverage": "turbo run coverage",
"dev": "turbo run dev --parallel",
"lint": "turbo run lint",
"check:format": "prettier --check \"**/*.{ts,tsx,md}\"",
"check": "pnpm lint && pnpm check:format",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"release": "changeset publish"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/slimfast-node/src/slimfast/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe, expect, test } from 'vitest';

import { SlimFast } from '.';
import before from '../../test-results/basic/before';
import after from '../../test-results/basic/after';
import before from '../../test-results/basic/before';

import type { SlimFastOpts } from '../types';

Expand Down
8 changes: 4 additions & 4 deletions packages/slimfast-node/src/slimfast/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Codebase } from '@modular-rocks/workspace-node';
import { SlimFast as SlimFastBase } from '@modular-rocks/slimfast';
import { Codebase } from '@modular-rocks/workspace-node';

import { ExpressionVisitor } from './visitors/expression';
import { defaultFunctionNameGenerator } from './pipeline/name/default-function-name-generator';
import { build } from './pipeline/build';
import { builder as pipelineBuilder } from './pipeline/build/builder';
import { extract } from './pipeline/extract';
import { build } from './pipeline/build';
import { name } from './pipeline/name';
import { defaultFunctionNameGenerator } from './pipeline/name/default-function-name-generator';
import { ExpressionVisitor } from './visitors/expression';

import type { SlimFastOpts } from '../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import unique from 'array-unique';
import traverse from '@babel/traverse';
import { program } from '@babel/types';
import traverse, { Binding, NodePath } from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import unique from 'array-unique';
import { describe, expect, test } from 'vitest';

import { combineImports } from '.';
import { parser } from '../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../visitors/utils/parser';

import type { RandomObject, SlimFastOpts } from '../../../../../types';
import type { Binding, NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { dirname, relative, resolve } from 'path/posix';

import { Binding } from '@babel/traverse';
import {
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
identifier,
importDeclaration,
importDefaultSpecifier,
Expand All @@ -15,6 +11,12 @@ import {
import unique from 'array-unique';

import type { RandomObject } from '../../../../../types';
import type { Binding } from '@babel/traverse';
import type {
ImportDefaultSpecifier,
ImportNamespaceSpecifier,
ImportSpecifier,
} from '@babel/types';

interface Entry {
default?: string | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import unique from 'array-unique';
import { program } from '@babel/types';
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { generateImportDeclaration } from '.';
import { parser } from '../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { dirname, extname, resolve } from 'path/posix';

import { NodePath } from '@babel/traverse';
import { program } from '@babel/types';
import unique from 'array-unique';

Expand All @@ -10,6 +9,7 @@ import { replace as replaceInOriginalFile } from './replace';
import { wrap } from './wrap';

import type { RandomObject, SlimFastOpts } from '../../../../types';
import type { NodePath } from '@babel/traverse';

/**
* Builds the AST for a module, manages its imports, and optionally replaces nodes in the original file.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { replace } from '.';
import { parser } from '../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NodePath } from '@babel/traverse';

import { generateJSXElement } from './jsx-function';
import { generateFunction as generateCalleeFunction } from './normal-function';

import type { RandomObject, SlimFastOpts } from '../../../../../types';
import type { NodePath } from '@babel/traverse';

/**
* Replaces a `node path` with a newly generated AST node, which could be a JSX element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { generateJSXElement } from '.';
import { parser } from '../../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import unique from 'array-unique';
import {
jsxIdentifier,
jsxOpeningElement,
Expand All @@ -8,6 +7,7 @@ import {
identifier,
jsxClosingElement,
} from '@babel/types';
import unique from 'array-unique';

import type { RandomObject } from '../../../../../../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { generateFunction } from '.';
import { parser } from '../../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unique from 'array-unique';
import { identifier, callExpression } from '@babel/types';
import unique from 'array-unique';

import type { RandomObject } from '../../../../../../types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import unique from 'array-unique';
import { program } from '@babel/types';
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { hasAwait } from '.';
import { parser } from '../../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';

import type { NodePath } from '@babel/traverse';

/**
* Checks if the provided AST node path contains an `await` expression.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { wrap } from '.';
import { parser } from '../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NodePath } from '@babel/traverse';

import { generateExportedJSXComponent } from './jsx-function';
import { generateExportedFunction } from './normal-function';

import type { RandomObject, SlimFastOpts } from '../../../../../types';
import type { NodePath } from '@babel/traverse';

/**
* Wraps the provided AST node path into an exported default function or JSX component.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { generateExportedJSXComponent } from '.';
import { parser } from '../../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import unique from 'array-unique';
import { NodePath } from '@babel/traverse';
import {
exportDefaultDeclaration,
functionDeclaration,
Expand All @@ -10,11 +8,14 @@ import {
variableDeclarator,
objectProperty,
objectPattern,
Statement,
} from '@babel/types';
import unique from 'array-unique';

import { hasAwait } from '../has-await';

import type { RandomObject } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';
import type { Statement } from '@babel/types';

/**
* Generates an exported JSX component declaration from a given AST node path and associated data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import traverse, { NodePath } from '@babel/traverse';
import traverse from '@babel/traverse';
import { Codebase, FileContainer } from '@modular-rocks/workspace-node';
import { describe, expect, test } from 'vitest';

import { generateExportedFunction } from '.';
import { parser } from '../../../../../visitors/utils/parser';
import { extractIdentifiers } from '../../../../../visitors/utils/extract-identifiers';
import { parser } from '../../../../../visitors/utils/parser';

import type { SlimFastOpts } from '../../../../../../types';
import type { NodePath } from '@babel/traverse';

const files: [string, string][] = [[`/path`, '']];
const opts: SlimFastOpts = {
Expand Down
Loading

0 comments on commit f71ecd7

Please sign in to comment.