Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve eslint config #2042

Merged
merged 11 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@types
download
dist
test/fixtures
bin
link
73 changes: 73 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
amio marked this conversation as resolved.
Show resolved Hide resolved
extends:
- airbnb
- prettier
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: 2018
sourceType: module
modules: true
plugins:
- '@typescript-eslint'
settings:
import/resolver:
typescript: {}
rules:
quotes: [2, 'single', { "allowTemplateLiterals": true }]
class-methods-use-this: 0
consistent-return: 0
func-names: 0
global-require: 0
guard-for-in: 0
import/no-duplicates: 0
import/no-dynamic-require: 0
import/no-extraneous-dependencies: 0
import/prefer-default-export: 0
lines-between-class-members: 0
no-await-in-loop: 0
no-bitwise: 0
no-console: 0
no-continue: 0
no-control-regex: 0
no-empty: 0
no-loop-func: 0
no-nested-ternary: 0
no-param-reassign: 0
no-plusplus: 0
no-restricted-globals: 0
no-restricted-syntax: 0
no-shadow: 0
no-underscore-dangle: 0
no-use-before-define: 0
prefer-const: 0
prefer-destructuring: 0
camelcase: 0 # in favor of '@typescript-eslint/camelcase'
# '@typescript-eslint/camelcase': 1
no-unused-vars: 0 # in favor of '@typescript-eslint/no-unused-vars'
# '@typescript-eslint/no-unused-vars': 1
# indent: 0 # in favor of '@typescript-eslint/indent'
# '@typescript-eslint/indent': ['error', 2] # this might conflict with a lot ongoing changes
'@typescript-eslint/no-array-constructor': error
'@typescript-eslint/adjacent-overload-signatures': error
# '@typescript-eslint/array-type': error
# '@typescript-eslint/ban-types': error
'@typescript-eslint/class-name-casing': error
# '@typescript-eslint/explicit-function-return-type': warn
# '@typescript-eslint/explicit-member-accessibility': error
'@typescript-eslint/interface-name-prefix': error
# '@typescript-eslint/member-delimiter-style': error
# '@typescript-eslint/no-angle-bracket-type-assertion': error
'@typescript-eslint/no-empty-interface': error
# '@typescript-eslint/no-explicit-any': warn
'@typescript-eslint/no-inferrable-types': error
'@typescript-eslint/no-misused-new': error
'@typescript-eslint/no-namespace': error
'@typescript-eslint/no-non-null-assertion': error
# '@typescript-eslint/no-object-literal-type-assertion': error # 2 errors
'@typescript-eslint/no-parameter-properties': error
'@typescript-eslint/no-triple-slash-reference': error
# '@typescript-eslint/no-use-before-define': error
# '@typescript-eslint/no-var-requires': error
# '@typescript-eslint/prefer-interface': error
'@typescript-eslint/prefer-namespace-keyword': error
'@typescript-eslint/type-annotation-spacing': error
68 changes: 7 additions & 61 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "yarn test-lint",
"test-unit": "nyc ava test/*unit.js --fail-fast",
"test-integration": "ava test/integration.js --serial --fail-fast",
"test-lint": "eslint .",
"test-lint": "eslint . --ext .js,.ts",
"prepublishOnly": "yarn build-download && cp download/default.js download/dist/now",
"coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov",
"postinstall": "node download/install.js",
Expand Down Expand Up @@ -68,60 +68,6 @@
"node10-win-x64"
]
},
"eslintConfig": {
"extends": [
"airbnb",
"prettier"
],
"parser": "@typescript-eslint/parser",
"plugins": [
"typescript"
],
"settings": {
"import/resolver": {
"typescript": {}
}
},
"rules": {
"camelcase": 0,
"class-methods-use-this": 0,
"consistent-return": 0,
"func-names": 0,
"global-require": 0,
"guard-for-in": 0,
"import/no-duplicates": 0,
"import/no-dynamic-require": 0,
"import/no-extraneous-dependencies": 0,
"import/prefer-default-export": 0,
"lines-between-class-members": 0,
"no-await-in-loop": 0,
"no-bitwise": 0,
"no-console": 0,
"no-continue": 0,
"no-control-regex": 0,
"no-empty": 0,
"no-loop-func": 0,
"no-nested-ternary": 0,
"no-param-reassign": 0,
"no-plusplus": 0,
"no-restricted-globals": 0,
"no-restricted-syntax": 0,
"no-shadow": 0,
"no-underscore-dangle": 0,
"no-use-before-define": 0,
"prefer-const": 0,
"prefer-destructuring": 0,
"typescript/no-unused-vars": "error"
}
},
"eslintIgnore": [
"@types",
"download",
"dist",
"test/fixtures",
"bin",
"link"
],
"ava": {
"compileEnhancements": false,
"extensions": [
Expand Down Expand Up @@ -163,6 +109,7 @@
"@types/tar-fs": "1.16.1",
"@types/text-table": "0.2.0",
"@types/write-json-file": "2.2.1",
"@typescript-eslint/eslint-plugin": "1.6.0",
"@typescript-eslint/parser": "1.1.0",
"@zeit/dockerignore": "0.0.4",
"@zeit/fun": "0.6.0",
Expand Down Expand Up @@ -194,14 +141,13 @@
"email-prompt": "0.3.2",
"email-validator": "1.1.1",
"epipebomb": "1.0.0",
"eslint": "5.3.0",
"eslint": "5.16.0",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "3.3.0",
"eslint-config-prettier": "4.1.0",
"eslint-import-resolver-typescript": "1.1.1",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "6.1.1",
"eslint-plugin-react": "7.11.0",
"eslint-plugin-typescript": "0.14.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"esm": "3.0.84",
"execa": "0.9.0",
"fetch-h2": "2.0.3",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/alias/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ export default async function set(
);
if (handleResult === 1) {
return 1;
} else {
amio marked this conversation as resolved.
Show resolved Hide resolved
}
console.log(`${chalk.cyan('> Success!')} ${chalk.bold(`https://${handleResult.alias}`)} now points to https://${deployment.url} ${setStamp()}`);
}

}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/commands/deploy/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ async function sync({
// Read scale and fail if we have both regions and scale
if (regions.length > 0 && Object.keys(scaleFromConfig).length > 0) {
error(
"Can't set both `regions` and `scale` options simultaneously",
'Can\'t set both `regions` and `scale` options simultaneously',
'regions-and-scale-at-once'
);
await exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/lib/builder-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function installBuilders(packages: string[]): Promise<void> {
for (const builderPkg of packages) {
const parsed = npa(builderPkg);
const name = parsed.name || builderPkg;
if (localBuilders.hasOwnProperty(name)) {
if (Object.hasOwnProperty.call(localBuilders, name)) {
continue;
}
const spec = parsed.rawSpec || parsed.fetchSpec || 'latest';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/lib/dev-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function executeBuild(
): Promise<void> {
const { buildConfig, buildEntry } = asset;
if (!buildConfig || !buildEntry) {
throw new Error("Asset has not been built yet, can't rebuild");
throw new Error('Asset has not been built yet, can\'t rebuild');
}
const { cwd, env } = devServer;
const entrypoint = relative(cwd, buildEntry.fsPath);
Expand Down
4 changes: 3 additions & 1 deletion src/commands/dev/lib/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ export default class DevServer {
if (this.stopping) return;
this.stopping = true;
this.output.log(`Stopping ${chalk.bold('`now dev`')} server`);
/* eslint-disable-next-line array-callback-return */
const ops = Object.values(this.assets).map((asset: BuilderOutput) => {
if (asset.type === 'Lambda' && asset.fn) {
return asset.fn.destroy();
Expand Down Expand Up @@ -501,6 +502,7 @@ export default class DevServer {
}
}

/* eslint-disable no-case-declarations */
switch (asset.type) {
case 'FileFsRef':
this.setResponseHeaders(res, nowRequestId);
Expand Down Expand Up @@ -590,7 +592,7 @@ export default class DevServer {
'UNKNOWN_ASSET_TYPE',
`Don't know how to handle asset type: ${(asset as any).type}`
);
return;

}
};

Expand Down
5 changes: 3 additions & 2 deletions src/commands/dev/lib/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export async function glob(
? (val: string): boolean => ignore.ignores(val)
: () => false;
delete opts.ignore;
/* eslint-disable no-new */
// @ts-ignore
new GlobIgnore(
pattern,
Expand Down Expand Up @@ -154,14 +155,14 @@ export async function globBuilderInputs(

for (const relativePath of files) {
const fsPath = join(options.cwd || '/', relativePath);
let stat: Stats = options.statCache![fsPath] as Stats;
let stat: Stats = options.statCache[fsPath] as Stats;
amio marked this conversation as resolved.
Show resolved Hide resolved
if (!stat) {
throw new Error(
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
);
}
if (stat.isFile()) {
const isSymlink = options.symlinks![fsPath];
const isSymlink = options.symlinks[fsPath];
if (isSymlink) {
stat = await lstat(fsPath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import http from 'http';
import { Output } from '../../../util/output';
import { Lambda as FunLambda } from '@zeit/fun';
import { FileBlob, FileFsRef, Lambda } from '@now/build-utils';
import { Output } from '../../../util/output';

export enum DevServerStatus {
busy,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/domains/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export default async function move(
client,
context,
domainName,
matchId ? matchId : destination
matchId || destination
);
});
if (moveTokenResult instanceof ERRORS.DomainMoveConflict) {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/init/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,13 @@ function prepareFolder(cwd: string, folder: string, force?: boolean) {
`Destination path "${chalk.bold(folder)}" already exists and is not an empty directory. You may use ${cmd('--force')} or ${cmd('--f')} to override it.`
);
}
} else {
if (dest !== cwd) {
} else if (dest !== cwd) {
try {
fs.mkdirSync(dest);
} catch (e) {
throw new Error(`Could not create directory "${chalk.bold(folder)}".`);
}
}
}

return dest;
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/alias/deployment-should-downscale.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import deploymentIsAliased from './deployment-is-aliased';
import { Output } from '../output';
import Client from '../client';
import getScaleForDC from '../../util/scale/get-scale-for-dc';
import getScaleForDC from '../scale/get-scale-for-dc';
import { Deployment } from '../../types';

export default async function deploymentShouldDownscale(
Expand Down
4 changes: 2 additions & 2 deletions src/util/alias/get-deployment-for-alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import chalk from 'chalk';

import getAppLastDeployment from '../deploy/get-app-last-deployment';
import getAppName from '../deploy/get-app-name';
import fetchDeploymentByIdOrHost from '../../util/deploy/get-deployment-by-id-or-host';
import wait from '../../util/output/wait';
import fetchDeploymentByIdOrHost from '../deploy/get-deployment-by-id-or-host';
import wait from '../output/wait';
import Client from '../client';
import { Output } from '../output';
import { User, Config } from '../../types';
Expand Down
4 changes: 2 additions & 2 deletions src/util/alias/get-inferred-targets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Output } from '../output';
import * as ERRORS from '../../util/errors-ts';
import * as ERRORS from '../errors-ts';
import { Config } from '../../types';
import cmd from '../../util/output/cmd';
import cmd from '../output/cmd';

export default async function getInferredTargets(
output: Output,
Expand Down
6 changes: 3 additions & 3 deletions src/util/alias/get-rules-from-file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import * as ERRORS from '../../util/errors-ts';
import humanizePath from '../../util/humanize-path';
import readJSONFile from '../../util/read-json-file';
import * as ERRORS from '../errors-ts';
import humanizePath from '../humanize-path';
import readJSONFile from '../read-json-file';
import validatePathAliasRules from './validate-path-alias-rules';
import { PathRule } from '../../types';

Expand Down
2 changes: 1 addition & 1 deletion src/util/alias/get-targets-for-alias.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NowError } from '../now-error';
import { Output } from '../output';
import getInferredTargets from './get-inferred-targets';
import toHost from '../../util/to-host';
import toHost from '../to-host';
import { Config } from '../../types';

export default async function getTargetsForAlias(
Expand Down
2 changes: 1 addition & 1 deletion src/util/alias/validate-path-alias-rules.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RulesFileValidationError } from '../../util/errors-ts';
import { RulesFileValidationError } from '../errors-ts';
import { PathRule } from '../../types';

export default function validatePathAliasRules(
Expand Down
2 changes: 1 addition & 1 deletion src/util/certs/issue-cert.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import retry from 'async-retry';
import { Cert } from '../../types';
import Client from '../client';
import retry from 'async-retry';

// When it's a configuration error we should retry because of the DNS propagation
// otherwise we bail to handle the error in the upper level
Expand Down
2 changes: 1 addition & 1 deletion src/util/config/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function getAuthConfigFilePath() {
}

export function readLocalConfig(prefix: string = process.cwd()) {
let target: string = '';
let target = '';

try {
target = getLocalPathConfig(prefix || process.cwd());
Expand Down
2 changes: 1 addition & 1 deletion src/util/config/get-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const getDefaultAuthConfig = async existing => {

const config = {
_:
"This is your Now credentials file. DON'T SHARE! More: https://bit.ly/2qAK8bb"
'This is your Now credentials file. DON\'T SHARE! More: https://bit.ly/2qAK8bb'
};

if (existing) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/deploy/get-app-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { NowError } from '../../util/now-error';
import { NowError } from '../now-error';
import { Output } from '../output';
import { Config } from '../../types';
import readPackage from '../read-package';
Expand Down