Skip to content

Commit

Permalink
Enforce import order
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinovantes committed May 5, 2022
1 parent 9a28c1f commit e2f4aee
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 26 deletions.
16 changes: 16 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ module.exports = {
'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/no-extraneous-dependencies': 'off',
'import/order': ['error', {
warnOnUnassignedImports: true,
alphabetize: {
order: 'asc',
caseInsensitive: false,
},
pathGroups: [
{
'pattern': '@/**',
'group': 'parent',
},
],
groups: [
'builtin', 'external', 'parent', 'sibling', 'index', 'object', 'type',
],
}],

'comma-dangle': 'off',
'@typescript-eslint/comma-dangle': ['error', 'always-multiline'],
Expand Down
6 changes: 3 additions & 3 deletions example/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useSSRContext } from '@vue/runtime-core'
import { Quasar } from 'quasar/src/index.all'
import { createSSRApp } from 'vue'
import App from './components/App.vue'
import { createAppRouter } from './router'
import type { createRouter } from 'vue-router'
import type { SSRContext } from '@vue/server-renderer'
import { useSSRContext } from '@vue/runtime-core'
import type express from 'express'
import { Quasar } from 'quasar/src/index.all'
import type { createRouter } from 'vue-router'

interface CreatedApp {
app: ReturnType<typeof createSSRApp>
Expand Down
8 changes: 4 additions & 4 deletions example/src/entryServer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import express from 'express'
import http from 'http'
import assert from 'assert'
import { VueSsrAssetRenderer } from 'vue-ssr-assets-plugin'
import http from 'http'
import path from 'path'
import { renderToString } from '@vue/server-renderer'
import express from 'express'
import { VueSsrAssetRenderer } from 'vue-ssr-assets-plugin'
import { AppContext, createApp } from './app'
import path from 'path'

// -----------------------------------------------------------------------------
// Express
Expand Down
2 changes: 1 addition & 1 deletion example/src/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SSRContext } from '@vue/server-renderer'
import { createMemoryHistory, createRouter, createWebHistory, type Router } from 'vue-router'
import type { SSRContext } from '@vue/server-renderer'

// ----------------------------------------------------------------------------
// Router
Expand Down
8 changes: 4 additions & 4 deletions example/webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import path from 'path'
import { Configuration, DefinePlugin } from 'webpack'
import { VueLoaderPlugin } from 'vue-loader'
import merge from 'webpack-merge'
import nodeExternals from 'webpack-node-externals'
import CopyWebpackPlugin from 'copy-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import { VueLoaderPlugin } from 'vue-loader'
import { VueSsrAssetsClientPlugin, VueSsrAssetsServerPlugin } from 'vue-ssr-assets-plugin'
import { Configuration, DefinePlugin } from 'webpack'
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'
import merge from 'webpack-merge'
import nodeExternals from 'webpack-node-externals'
import { QuasarUnusedPlugin } from '../src'

// ----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/utils/findCallExpressions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CallExpression, Node } from 'estree'
import { visitChildren } from './visitChildren'
import type { CallExpression, Node } from 'estree'

export function findCallExpressions(root: Node, calleeName: string): Array<CallExpression> {
const isTargetCallExpression = (node: Node): node is CallExpression => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/findImportLocalId.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ImportDefaultSpecifier, ImportSpecifier, Node } from 'estree'
import { visitChildren } from './visitChildren'
import type { ImportDefaultSpecifier, ImportSpecifier, Node } from 'estree'

export function findImportLocalId(root: Node, importSource: string, importName: string): string | undefined {
const search = (node: Node): ImportSpecifier | ImportDefaultSpecifier | undefined => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/stringifyEstree.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Node } from 'estree'
import { isEstreeNode } from './isEstreeNode'
import type { Node } from 'estree'

export function stringifyEstree(root: Node): string {
let str = ''
Expand Down
2 changes: 1 addition & 1 deletion src/utils/visitChildren.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Node } from 'estree'
import { isEstreeNode } from './isEstreeNode'
import type { Node } from 'estree'

export function visitChildren<T>(node: Node, visitNode: (node: Node) => T | undefined): T | undefined {
for (const value of Object.values(node)) {
Expand Down
2 changes: 1 addition & 1 deletion src/webpack/QuasarUnusedLoader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PLUGIN_NAME, QUASAR_INDEX_FILE } from '../Constants'
import type { LoaderContext } from 'webpack'
import type { QuasarUnusedLoaderOptions } from './QuasarUnusedLoaderOptions'
import type { LoaderContext } from 'webpack'

// eslint-disable-next-line @typescript-eslint/naming-convention
export function QuasarUnusedLoader(this: LoaderContext<QuasarUnusedLoaderOptions>, source: string): string {
Expand Down
16 changes: 8 additions & 8 deletions src/webpack/QuasarUnusedPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import assert from 'assert'
import { existsSync } from 'fs'
import path from 'path'
import quasarAutoImportJson from 'quasar/dist/transforms/auto-import.json'
import quasarJson from 'quasar/package.json'
import { WebpackPluginInstance, Compiler, javascript, NormalModule, Compilation } from 'webpack'
import { PLUGIN_NAME, QUASAR_INDEX_FILE } from '../Constants'
import quasarAutoImportJson from 'quasar/dist/transforms/auto-import.json'
import { findCallExpressions } from '../utils/findCallExpressions'
import { findImportLocalId } from '../utils/findImportLocalId'
import { QuasarUnusedPluginOptions, validateQuasarUnusedPluginOptions } from './QuasarUnusedPluginOptions'
import { ReplaceValueDependency } from './ReplaceValueDependency'
import quasarJson from 'quasar/package.json'
import path from 'path'
import { existsSync } from 'fs'
import type { QuasarUnusedLoaderOptions } from './QuasarUnusedLoaderOptions'
import { QuasarUnusedPluginOptions, validateQuasarUnusedPluginOptions } from './QuasarUnusedPluginOptions'
import { findImportLocalId } from '../utils/findImportLocalId'
import { findCallExpressions } from '../utils/findCallExpressions'
import assert from 'assert'

interface QuasarAutoImport {
importName: Record<string, string>
Expand Down
2 changes: 1 addition & 1 deletion src/webpack/ReplaceValueDependency.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PLUGIN_NAME } from '../Constants'
import { Dependency, javascript, Generator, sources } from 'webpack'
import { PLUGIN_NAME } from '../Constants'

type DependencyTemplate = ReturnType<Parameters<Generator['generate']>[1]['dependencyTemplates']['get']>
type Expression = Parameters<javascript.JavascriptParser['evaluateExpression']>[0]
Expand Down

0 comments on commit e2f4aee

Please sign in to comment.