Add lots of linting

This commit is contained in:
Jonathan Clem committed 2019-05-21 17:08:25 -04:00
1 parent 7ee9cbe61a
commit cca8b40ef2
3 files changed
+28 -25

No files matched your search

+7 -4
View File
@@ -1,6 +1,9 @@
import {ExitCode} from '@actions/exit'
import * as os from 'os' import * as os from 'os'
import * as core from '../src/core' import * as core from '../src/core'
/* eslint-disable @typescript-eslint/unbound-method */
const testEnvVars = { const testEnvVars = {
'my var': '', 'my var': '',
'special char var \r\n];': '', 'special char var \r\n];': '',
@@ -103,18 +106,18 @@ describe('@actions/core', () => {
it('setNeutral sets the correct exit code', () => { it('setNeutral sets the correct exit code', () => {
core.setFailed('Failure message') core.setFailed('Failure message')
expect(process.exitCode).toBe(1) expect(process.exitCode).toBe(ExitCode.Failure)
}) })
it('setFailure sets the correct exit code and failure message', () => { it('setFailure sets the correct exit code and failure message', () => {
core.setFailed('Failure message') core.setFailed('Failure message')
expect(process.exitCode).toBe(1) expect(process.exitCode).toBe(ExitCode.Failure)
assertWriteCalls([`##[error]Failure message${os.EOL}`]) assertWriteCalls([`##[error]Failure message${os.EOL}`])
}) })
it('setFailure escapes the failure message', () => { it('setFailure escapes the failure message', () => {
core.setFailed('Failure \r\n\nmessage\r') core.setFailed('Failure \r\n\nmessage\r')
expect(process.exitCode).toBe(1) expect(process.exitCode).toBe(ExitCode.Failure)
assertWriteCalls([`##[error]Failure %0D%0A%0Amessage%0D${os.EOL}`]) assertWriteCalls([`##[error]Failure %0D%0A%0Amessage%0D${os.EOL}`])
}) })
@@ -150,7 +153,7 @@ describe('@actions/core', () => {
}) })
// Assert that process.stdout.write calls called only with the given arguments. // Assert that process.stdout.write calls called only with the given arguments.
function assertWriteCalls(calls: string[]) { function assertWriteCalls(calls: string[]): void {
expect(process.stdout.write).toHaveBeenCalledTimes(calls.length) expect(process.stdout.write).toHaveBeenCalledTimes(calls.length)
for (let i = 0; i < calls.length; i++) { for (let i = 0; i < calls.length; i++) {
+14 -14
View File
@@ -2,6 +2,10 @@ import * as os from 'os'
// For internal use, subject to change. // For internal use, subject to change.
interface CommandProperties {
[key: string]: string
}
/** /**
* Commands * Commands
* *
@@ -14,25 +18,25 @@ import * as os from 'os'
*/ */
export function issueCommand( export function issueCommand(
command: string, command: string,
properties: any, properties: CommandProperties,
message: string message: string
) { ): void {
const cmd = new Command(command, properties, message) const cmd = new Command(command, properties, message)
process.stdout.write(cmd.toString() + os.EOL) process.stdout.write(cmd.toString() + os.EOL)
} }
export function issue(name: string, message: string) { export function issue(name: string, message: string): void {
issueCommand(name, {}, message) issueCommand(name, {}, message)
} }
const CMD_PREFIX = '##[' const CMD_PREFIX = '##['
class Command { class Command {
constructor( private readonly command: string
command: string, private readonly message: string
properties: {[key: string]: string}, private readonly properties: CommandProperties
message: string
) { constructor(command: string, properties: CommandProperties, message: string) {
if (!command) { if (!command) {
command = 'missing.command' command = 'missing.command'
} }
@@ -42,11 +46,7 @@ class Command {
this.message = message this.message = message
} }
command: string toString(): string {
message: string
properties: {[key: string]: string}
toString() {
let cmdStr = CMD_PREFIX + this.command let cmdStr = CMD_PREFIX + this.command
if (this.properties && Object.keys(this.properties).length > 0) { if (this.properties && Object.keys(this.properties).length > 0) {
@@ -67,7 +67,7 @@ class Command {
// safely append the message - avoid blowing up when attempting to // safely append the message - avoid blowing up when attempting to
// call .replace() if message is not a string for some reason // call .replace() if message is not a string for some reason
const message: string = `${this.message || ''}` const message = `${this.message || ''}`
cmdStr += escapeData(message) cmdStr += escapeData(message)
return cmdStr return cmdStr
+7 -7
View File
@@ -18,7 +18,7 @@ export interface InputOptions {
* @param name the name of the variable to set * @param name the name of the variable to set
* @param val the value of the variable * @param val the value of the variable
*/ */
export function exportVariable(name: string, val: string) { export function exportVariable(name: string, val: string): void {
process.env[name] = val process.env[name] = val
issueCommand('set-env', {name}, val) issueCommand('set-env', {name}, val)
} }
@@ -28,7 +28,7 @@ export function exportVariable(name: string, val: string) {
* @param name the name of the variable to set * @param name the name of the variable to set
* @param val value of the secret * @param val value of the secret
*/ */
export function exportSecret(name: string, val: string) { export function exportSecret(name: string, val: string): void {
exportVariable(name, val) exportVariable(name, val)
issueCommand('set-secret', {}, val) issueCommand('set-secret', {}, val)
} }
@@ -57,7 +57,7 @@ export function getInput(name: string, options?: InputOptions): string {
/** /**
* Sets the action status to neutral * Sets the action status to neutral
*/ */
export function setNeutral() { export function setNeutral(): void {
process.exitCode = ExitCode.Neutral process.exitCode = ExitCode.Neutral
} }
@@ -66,7 +66,7 @@ export function setNeutral() {
* When the action exits it will be with an exit code of 1 * When the action exits it will be with an exit code of 1
* @param message add error issue message * @param message add error issue message
*/ */
export function setFailed(message: string) { export function setFailed(message: string): void {
process.exitCode = ExitCode.Failure process.exitCode = ExitCode.Failure
error(message) error(message)
} }
@@ -79,7 +79,7 @@ export function setFailed(message: string) {
* Writes debug message to user log * Writes debug message to user log
* @param message debug message * @param message debug message
*/ */
export function debug(message: string) { export function debug(message: string): void {
issueCommand('debug', {}, message) issueCommand('debug', {}, message)
} }
@@ -87,7 +87,7 @@ export function debug(message: string) {
* Adds an error issue * Adds an error issue
* @param message error issue message * @param message error issue message
*/ */
export function error(message: string) { export function error(message: string): void {
issue('error', message) issue('error', message)
} }
@@ -95,6 +95,6 @@ export function error(message: string) {
* Adds an warning issue * Adds an warning issue
* @param message warning issue message * @param message warning issue message
*/ */
export function warning(message: string) { export function warning(message: string): void {
issue('warning', message) issue('warning', message)
} }