From 4159004dd400148df9887f6aaefb696548704b8e Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 2 Nov 2019 07:35:20 -0500 Subject: [PATCH] lint: remove confusing *sync wrapper names --- config/rollup.js | 2 +- src/config/index.ts | 4 ++-- src/rule/SchemaRule.ts | 2 +- src/rule/index.ts | 4 ++-- src/source.ts | 12 ++++++------ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/config/rollup.js b/config/rollup.js index 1b88075..8af5d1c 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -84,8 +84,8 @@ const bundle = { 'node_modules/noicejs/out/main-bundle.js': [ 'BaseError', 'ConsoleLogger', - 'logWithLevel', 'NullLogger', + 'logWithLevel', ], 'node_modules/js-yaml/index.js': [ 'DEFAULT_SAFE_SCHEMA', diff --git a/src/config/index.ts b/src/config/index.ts index 16a4023..cefbab9 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,7 +5,7 @@ import { join } from 'path'; import { NotFoundError } from '../error/NotFoundError'; import { YamlParser } from '../parser/YamlParser'; -import { readFileSync } from '../source'; +import { readFile } from '../source'; import { CONFIG_ENV, CONFIG_SCHEMA } from './schema'; import { includeSchema } from './type/Include'; @@ -70,7 +70,7 @@ export async function readConfig(path: string): Promise { try { // need to await this read to catch the error, need to catch the error to check the code // tslint:disable-next-line:prefer-immediate-return - const data = await readFileSync(path, { + const data = await readFile(path, { encoding: 'utf-8', }); return data; diff --git a/src/rule/SchemaRule.ts b/src/rule/SchemaRule.ts index b41bed2..c6e7d67 100644 --- a/src/rule/SchemaRule.ts +++ b/src/rule/SchemaRule.ts @@ -67,7 +67,7 @@ export class SchemaRule implements RuleData, Visitor { if (filter(node)) { ctx.logger.debug({ item: node }, 'checking item'); - if (!check(node) && !isNil(check.errors) && check.errors.length > 0) { + if (!check(node) && hasItems(check.errors)) { ctx.error(...Array.from(check.errors).map(friendlyError)); } } else { diff --git a/src/rule/index.ts b/src/rule/index.ts index 067d479..4275fe3 100644 --- a/src/rule/index.ts +++ b/src/rule/index.ts @@ -2,7 +2,7 @@ import { Dictionary, intersection, isNil } from 'lodash'; import { LogLevel } from 'noicejs'; import { YamlParser } from '../parser/YamlParser'; -import { readFileSync } from '../source'; +import { readFile } from '../source'; import { ensureArray } from '../utils'; import { VisitorContext } from '../visitor/VisitorContext'; import { SchemaRule } from './SchemaRule'; @@ -52,7 +52,7 @@ export async function loadRules(paths: Array, ctx: VisitorContext): Prom const rules = []; for (const path of paths) { - const contents = await readFileSync(path, { + const contents = await readFile(path, { encoding: 'utf-8', }); diff --git a/src/source.ts b/src/source.ts index 15ef105..10a319b 100644 --- a/src/source.ts +++ b/src/source.ts @@ -1,18 +1,18 @@ -import { readFile, writeFile } from 'fs'; +import { readFile as readBack, writeFile as writeBack } from 'fs'; import { isNil } from 'lodash'; import { promisify } from 'util'; export const FILE_ENCODING = 'utf-8'; -export const readFileSync = promisify(readFile); -export const writeFileSync = promisify(writeFile); +export const readFile = promisify(readBack); +export const writeFile = promisify(writeBack); export async function loadSource(path: string): Promise { if (path === '-') { - return readFileSync(0, { + return readFile(0, { encoding: FILE_ENCODING, }); } else { - return readFileSync(path, { + return readFile(path, { encoding: FILE_ENCODING, }); } @@ -30,7 +30,7 @@ export async function writeSource(path: string, data: string): Promise { }); }); } else { - return writeFileSync(path, data, { + return writeFile(path, data, { encoding: FILE_ENCODING, }); }