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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] running lint as a seperate CI task and fixes all errors to ensure CI passes #463

Merged
merged 6 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
rules: {
'no-var': 'error',
'no-console': 'off',
'no-unused-vars': 'off', // this is turned off because of the lack of scope analysis on imported types (https://github.com/typescript-eslint/typescript-eslint/issues/1856)
gabrielcsapo marked this conversation as resolved.
Show resolved Hide resolved
'no-process-exit': 'off',
'object-shorthand': 'error',
'prettier/prettier': ['error', require('./prettier.config')],
Expand Down
15 changes: 9 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ on:
pull_request:
push:
# filtering branches here, prevents duplicate builds from pull_request and push
branches:
branches:
- master
- 'v*'
# always run CI for tags
tags:
- '*'
# early issue detection, run CI weekly on Sundays

# early issue detection, run CI weekly on Sundays
schedule:
- cron: '0 6 * * 0'

Expand All @@ -26,17 +26,20 @@ jobs:

steps:
- uses: actions/checkout@v1

- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v1
with:
version: ${{ matrix.node_version }}

- name: install yarn
run: npm install -g yarn cross-env

- name: install dependencies
run: yarn install --frozen-lockfile

- name: lint
run: yarn lint

- name: test
run: cross-env CI=true yarn test
run: cross-env CI=true yarn test
4 changes: 3 additions & 1 deletion lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ class Builder extends EventEmitter {

for (let nodeWrapper of this._nodeWrappers.values()) {
if (nodeWrapper.nodeInfo.nodeType === 'transform') {
(nodeWrapper as TransformNodeWrapper).inputPaths = nodeWrapper.inputNodeWrappers.map((nw: any) => nw.outputPath);
(nodeWrapper as TransformNodeWrapper).inputPaths = nodeWrapper.inputNodeWrappers.map(
(nw: any) => nw.outputPath
);
nodeWrapper.outputPath = this.mkTmpDir(nodeWrapper, 'out');

if (nodeWrapper.nodeInfo.needsCache) {
Expand Down
6 changes: 3 additions & 3 deletions lib/dummy-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Watcher extends EventEmitter {
builder: any;
currentBuild: any;
_lifetimeDeferred: {
promise?: Promise<void>,
promise?: Promise<void>;
resolve?: (value?: any) => void;
reject?: (error?: any) => void;
};
Expand Down Expand Up @@ -34,6 +34,6 @@ class Watcher extends EventEmitter {
this._lifetimeDeferred.resolve();
}
}
};
}

export = Watcher;
export = Watcher;
6 changes: 3 additions & 3 deletions lib/errors/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import wrapPrimitiveErrors from '../utils/wrap-primitive-errors';

interface BroccoliPayloadError {
originalError: Error;
originalMessage: string,
originalMessage: string;
nodeId: number;
nodeLabel: string;
nodeName: string;
Expand All @@ -15,7 +15,7 @@ interface BroccoliPayloadError {
treeDir: string;
line: number;
column: number;
},
};
}

export default class BuildError extends BuilderError {
Expand Down Expand Up @@ -87,4 +87,4 @@ export default class BuildError extends BuilderError {
},
};
}
};
}
2 changes: 1 addition & 1 deletion lib/errors/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ export default class BuilderError extends Error {

this.isBuilderError = true;
}
};
}
2 changes: 1 addition & 1 deletion lib/errors/cancelation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export default class Cancelation extends Error {
this.isCancelation = true;
this.isSilent = true;
}
};
}
2 changes: 1 addition & 1 deletion lib/errors/cli.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Base class for cli errors
export default class CliError extends Error {};
export default class CliError extends Error {}
2 changes: 1 addition & 1 deletion lib/errors/node-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ export default class NodeSetupError extends BuilderError {
// The stack will have the original exception name, but that's OK
this.stack = originalError.stack;
}
};
}
14 changes: 7 additions & 7 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export interface BrocfileOptions {
/**
* Environment setting. Default: development
* This option is set by the --environment/--prod/--dev CLI argument.
* This option can be used to conditionally affect a build pipeline in order to load different plugins for
* development/production/testing
*/
env: string;
/**
* Environment setting. Default: development
* This option is set by the --environment/--prod/--dev CLI argument.
* This option can be used to conditionally affect a build pipeline in order to load different plugins for
* development/production/testing
*/
env: string;
}
1 change: 1 addition & 0 deletions lib/load_brocfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function requireBrocfile(brocfilePath: string) {
}

// ESM `export default X` is represented as module.exports = { default: X }
// eslint-disable-next-line no-prototype-builtins
if (brocfile !== null && typeof brocfile === 'object' && brocfile.hasOwnProperty('default')) {
brocfile = brocfile.default;
}
Expand Down
40 changes: 23 additions & 17 deletions lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ interface MiddlewareOptions {
// Supported options:
// autoIndex (default: true) - set to false to disable directory listings
// liveReloadPath - LiveReload script URL for error pages
function handleRequest(outputPath: string, request: any, response: any, next: any, options: MiddlewareOptions) {
const urlObj = url.parse(request.url);
function handleRequest(
outputPath: string,
request: any,
response: any,
next: any,
options: MiddlewareOptions
) {
const urlObj = url.URL(request.url);
let pathname = urlObj.pathname || '';
let filename: string, stat, lastModified, buffer;

Expand Down Expand Up @@ -87,21 +93,21 @@ function handleRequest(outputPath: string, request: any, response: any, next: an
const context = {
url: request.url,
files: fs
.readdirSync(filename)
.sort()
.map(child => {
const stat = fs.statSync(path.join(filename, child)),
isDir = stat.isDirectory();
return {
href: child + (isDir ? '/' : ''),
type: isDir
? 'dir'
: path
.extname(child)
.replace('.', '')
.toLowerCase(),
};
}),
.readdirSync(filename)
.sort()
.map(child => {
const stat = fs.statSync(path.join(filename, child)),
isDir = stat.isDirectory();
return {
href: child + (isDir ? '/' : ''),
type: isDir
? 'dir'
: path
.extname(child)
.replace('.', '')
.toLowerCase(),
};
}),
liveReloadPath: options.liveReloadPath,
};
response.setHeader('Content-Type', 'text/html; charset=utf-8');
Expand Down
17 changes: 13 additions & 4 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ class Server extends EventEmitter {
_started: boolean;
ui: any;

constructor(watcher: Watcher, host: string, port: string, connect = require('connect'), ui: UI, ssl: boolean, sslKey: string, sslCert: string) {
constructor(
watcher: Watcher,
host: string,
port: string,
connect = require('connect'),
ui: UI,
ssl: boolean,
sslKey: string,
sslCert: string
) {
super();

this._watcher = watcher;
Expand Down Expand Up @@ -158,9 +167,9 @@ function serve(
ui.writeError(err);
_process.exit(1);
});
};
}

export = {
Server,
serve
}
serve,
};
2 changes: 1 addition & 1 deletion lib/utils/bind-file-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export default function bindFileEvent(
node.revise();
adapter.emit('change', event, filepath, root);
});
}
}
8 changes: 4 additions & 4 deletions lib/utils/calculate-summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ export default function calculateSummary(tree: HeimdallNode) {
let totalTime = 0;
let nodes: BaseNode[] = [];
let groupedNodes: GroupedNode[] = [];
let nodesGroupedByName: { [key: string]: GroupedNode; } = {};
let nodesGroupedByName: { [key: string]: GroupedNode } = {};

// calculate times
tree.visitPostOrder((node) => {
tree.visitPostOrder(node => {
let nonbroccoliChildrenTime = 0;
node.forEachChild((childNode) => {
node.forEachChild(childNode => {
// subsume non-broccoli nodes as their ancestor broccoli nodes'
// broccoliSelfTime
if (!childNode.id.broccoliNode) {
Expand Down Expand Up @@ -89,4 +89,4 @@ export default function calculateSummary(tree: HeimdallNode) {
nodes,
groupedNodes,
};
};
}
2 changes: 1 addition & 1 deletion lib/utils/filter-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default function filterMap<T>(iterator: Iterable<T>, cb: (entry: T) => bo
}
}
return result;
};
}
2 changes: 1 addition & 1 deletion lib/utils/slow-trees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function printSlowNodes(tree: HeimdallNode, factor: number, ui: U
ui.writeLine('Error when printing slow nodes', 'ERROR');
ui.writeError(e);
}
};
}

function pad(str: string, len: number, char?: string, dir?: 'left' | 'both') {
if (!char) {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/undefined-to-null.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Replace all `undefined` values with `null`, so that they show up in JSON output
export default function undefinedToNull(obj: { [index: string]: any }) {
for (const key in obj) {
// eslint-disable-next-line no-prototype-builtins
if (obj.hasOwnProperty(key) && obj[key] === undefined) {
obj[key] = null;
}
}
return obj;
};
}
2 changes: 1 addition & 1 deletion lib/utils/wrap-primitive-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default function wrapPrimitiveErrors(err: Error): Error {
// that the stack trace is not useful, or even set the .stack to null.
return new Error(err + '');
}
};
}
2 changes: 1 addition & 1 deletion lib/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Watcher extends EventEmitter {
_ready: boolean;
_quittingPromise: Promise<void> | null;
_lifetime: {
promise?: Promise<void>,
promise?: Promise<void>;
resolve?: (value: any) => void;
reject?: (error: any) => void;
} | null;
Expand Down
6 changes: 3 additions & 3 deletions lib/watcher_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class WatcherAdapter extends EventEmitter {

quit() {
let closing = this.watchers.map(
(watcher: sane.Watcher) =>
(watcher: sane.Watcher) =>
new Promise((resolve, reject) =>
// @ts-ignore
watcher.close((err: any) => {
Expand All @@ -79,6 +79,6 @@ class WatcherAdapter extends EventEmitter {
this.watchers.length = 0;
return Promise.all(closing).then(() => {});
}
};
}

export = WatcherAdapter;
export = WatcherAdapter;
4 changes: 2 additions & 2 deletions lib/wrappers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export default class NodeWrapper {

nodeInfoToJSON() {
return {};
};
};
}
}
2 changes: 1 addition & 1 deletion lib/wrappers/source-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export default class SourceNodeWrapper extends NodeWrapper {
// leave out instantiationStack
});
}
};
}
12 changes: 4 additions & 8 deletions lib/wrappers/transform-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { TransformNodeInfo, CallbackObject } from 'broccoli-node-api';
const logger = require('heimdalljs-logger')('broccoli:transform-node');

export default class TransformNodeWrapper extends NodeWrapper {
inputRevisions!: WeakMap<any, { revision: number, changed: boolean }>;
inputRevisions!: WeakMap<any, { revision: number; changed: boolean }>;
callbackObject!: CallbackObject;
inputPaths!: string[];
nodeInfo!: TransformNodeInfo;
Expand Down Expand Up @@ -69,7 +69,7 @@ export default class TransformNodeWrapper extends NodeWrapper {

if (!this.shouldBuild()) {
this.buildState.built = false;
return // Noop the build since inputs did not change
return; // Noop the build since inputs did not change
}

if (!this.nodeInfo.persistentOutput) {
Expand Down Expand Up @@ -100,11 +100,7 @@ export default class TransformNodeWrapper extends NodeWrapper {
}

if (this.buildState.selfTime >= 100) {
logger.debug(
`Node build execution time: %ds %dms`,
endTime[0],
Math.round(endTime[1] / 1e6)
);
logger.debug(`Node build execution time: %ds %dms`, endTime[0], Math.round(endTime[1] / 1e6));
}
}

Expand All @@ -131,4 +127,4 @@ export default class TransformNodeWrapper extends NodeWrapper {
// leave out instantiationStack (too long), inputNodes, and callbacks
});
}
};
}