Skip to content

Commit

Permalink
Lint for invalid imports (vercel#13482)
Browse files Browse the repository at this point in the history
This adds a lint rule to ensure we don't import dev dependencies by accident.
  • Loading branch information
Timer authored May 28, 2020
1 parent 5eafc1e commit bee8c31
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 26 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@
"settings": {
"react": {
"version": "detect"
}
},
"import/internal-regex": "^next/"
},
"overrides": [
{
"files": ["packages/**"],
"rules": {
"import/no-extraneous-dependencies": [
"error",
{ "devDependencies": false }
]
}
},
{
"files": ["test/**/*.test.js"],
"extends": ["plugin:jest/recommended"],
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/create-app.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import retry from 'async-retry'
import chalk from 'chalk'
import cpy from 'cpy'
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/helpers/examples.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import got from 'got'
import tar from 'tar'
import { Stream } from 'stream'
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/helpers/git.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import { execSync } from 'child_process'
import path from 'path'
import rimraf from 'rimraf'
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/helpers/install.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import chalk from 'chalk'
import spawn from 'cross-spawn'

Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/helpers/is-folder-empty.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import chalk from 'chalk'
import fs from 'fs'
import path from 'path'
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/helpers/validate-pkg.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import validateProjectName from 'validate-npm-package-name'

export function validateNpmName(
Expand Down
1 change: 1 addition & 0 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
/* eslint-disable import/no-extraneous-dependencies */
import chalk from 'chalk'
import Commander from 'commander'
import path from 'path'
Expand Down
3 changes: 2 additions & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
]
},
"peerDependencies": {
"next": "*"
"next": "*",
"react": "*"
}
}
3 changes: 2 additions & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"peerDependencies": {
"@material-ui/styles": "*",
"next": "*"
"next": "*",
"react": "*"
}
}
1 change: 1 addition & 0 deletions packages/next-polyfill-nomodule/src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
import 'core-js/features/array/copy-within'
import 'core-js/features/array/fill'
import 'core-js/features/array/find'
Expand Down
1 change: 1 addition & 0 deletions packages/next/build/bundles/autodll-webpack-plugin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
const path = require('path')

module.exports = (distDir) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/next/build/profiler/profiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path'
import fs from 'fs'
import path from 'path'

let inspector
try {
Expand Down Expand Up @@ -69,6 +69,7 @@ class Profiler {
}
}

// eslint-disable-next-line import/no-extraneous-dependencies
const { Tracer } = require('chrome-trace-event')

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { NodePath } from 'ast-types/lib/node-path'

export interface IConformanceAnomaly {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import {
IWebpackConformanceTest,
IGetAstNodeResult,
IParsedModuleDetails,
IConformanceTestResult,
IConformanceTestStatus,
} from '../TestInterface'
// eslint-disable-next-line import/no-extraneous-dependencies
import { namedTypes } from 'ast-types'
// eslint-disable-next-line import/no-extraneous-dependencies
import { NodePath } from 'ast-types/lib/node-path'
import { types } from 'next/dist/compiled/recast'
import {
CONFORMANCE_ERROR_PREFIX,
CONFORMANCE_WARNING_PREFIX,
} from '../constants'
import { types } from 'next/dist/compiled/recast'
import { NodePath } from 'ast-types/lib/node-path'
import { namedTypes } from 'ast-types'
import { getLocalFileName } from '../utils/file-utils'
import {
IConformanceTestResult,
IConformanceTestStatus,
IGetAstNodeResult,
IParsedModuleDetails,
IWebpackConformanceTest,
} from '../TestInterface'
import {
isNodeCreatingScriptElement,
reducePropsToObject,
} from '../utils/ast-utils'
import { getLocalFileName } from '../utils/file-utils'

function getMessage(
property: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
CONFORMANCE_ERROR_PREFIX,
CONFORMANCE_WARNING_PREFIX,
} from '../constants'
// eslint-disable-next-line import/no-extraneous-dependencies
import { namedTypes } from 'ast-types/'
// eslint-disable-next-line import/no-extraneous-dependencies
import { NodePath } from 'ast-types/lib/node-path'
import { getLocalFileName } from '../utils/file-utils'
import { isNodeCreatingScriptElement } from '../utils/ast-utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Compiler, compilation } from 'webpack'
// eslint-disable-next-line import/no-extraneous-dependencies
import { NodePath } from 'ast-types/lib/node-path'
import { visit } from 'next/dist/compiled/recast'
import { compilation, Compiler } from 'webpack'
import {
IConformanceTestResult,
IWebpackConformanceTest,
IConformanceAnomaly,
IConformanceTestResult,
IConformanceTestStatus,
IGetAstNodeResult,
IWebpackConformanceTest,
NodeInspector,
IConformanceTestStatus,
} from './TestInterface'
import { NodePath } from 'ast-types/lib/node-path'
import { visit } from 'next/dist/compiled/recast'

export { MinificationConformanceCheck } from './checks/minification-conformance-check'
export { ReactSyncScriptsConformanceCheck } from './checks/react-sync-scripts-conformance-check'
export { DuplicatePolyfillsConformanceCheck } from './checks/duplicate-polyfills-conformance-check'
export { GranularChunksConformanceCheck } from './checks/granular-chunks-conformance'
export { MinificationConformanceCheck } from './checks/minification-conformance-check'
export { ReactSyncScriptsConformanceCheck } from './checks/react-sync-scripts-conformance-check'

export interface IWebpackConformancePluginOptions {
tests: IWebpackConformanceTest[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { types } from 'next/dist/compiled/recast'
// eslint-disable-next-line import/no-extraneous-dependencies
import { namedTypes } from 'ast-types'
import { types } from 'next/dist/compiled/recast'

export function isNodeCreatingScriptElement(node: namedTypes.CallExpression) {
const callee = node.callee as namedTypes.Identifier
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/on-demand-entry-handler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { EventEmitter } from 'events'
import { IncomingMessage, ServerResponse } from 'http'
import WebpackDevMiddleware from 'next/dist/compiled/webpack-dev-middleware'
import { join, posix } from 'path'
import { stringify } from 'querystring'
import { parse } from 'url'
import webpack from 'webpack'
import WebpackDevMiddleware from 'webpack-dev-middleware'
import DynamicEntryPlugin from 'webpack/lib/DynamicEntryPlugin'
import { isWriteable } from '../build/is-writeable'
import * as Log from '../build/output/log'
Expand Down
1 change: 1 addition & 0 deletions packages/next/taskfile-ncc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const ncc = require('@zeit/ncc')
const { existsSync, readFileSync } = require('fs')
const { basename, dirname, extname, join } = require('path')
Expand Down
1 change: 1 addition & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line import/no-extraneous-dependencies
const notifier = require('node-notifier')
const relative = require('path').relative

Expand Down
1 change: 1 addition & 0 deletions packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-extraneous-dependencies */
declare module '@babel/plugin-transform-modules-commonjs'
declare module 'browserslist'
declare module 'cssnano-simple' {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/types/webpack.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/no-unused-vars */
// Type definitions for webpack 4.39
// Project: https://github.com/webpack/webpack
// Definitions by: Qubo <https://github.com/tkqubo>
Expand Down
1 change: 1 addition & 0 deletions packages/react-dev-overlay/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from 'source-map'
import { StackFrame } from 'stacktrace-parser'
import url from 'url'
// eslint-disable-next-line import/no-extraneous-dependencies
import webpack from 'webpack'
import { getRawSourceMap } from './internal/helpers/getRawSourceMap'
import { launchEditor } from './internal/helpers/launchEditor'
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6321,6 +6321,7 @@ eslint-module-utils@^2.4.1:
[email protected]:
version "2.20.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.20.2.tgz#91fc3807ce08be4837141272c8b99073906e588d"
integrity sha512-FObidqpXrR8OnCh4iNsxy+WACztJLXAHBO5hK79T1Hc77PgQZkyDGA5Ag9xAvRpglvLNxhH/zSmZ70/pZ31dHg==
dependencies:
array-includes "^3.0.3"
array.prototype.flat "^1.2.1"
Expand Down

0 comments on commit bee8c31

Please sign in to comment.