Skip to content

Commit da83847

Browse files
committed
tslinting, @onComplete
1 parent 18f57bf commit da83847

25 files changed

+64
-78
lines changed

Diff for: lib/build/parser/actions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function addToTasks(result, line, index) {
4040
result = doAction('hints', isActionArray, actionValue, result, line, index);
4141
break;
4242
case 'continue':
43-
result = doAction('continue', isActionArray, actionValue, result, line, index);
43+
break;
4444
case 'action':
4545
if (task.actions === undefined) {
4646
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];

Diff for: lib/build/parser/chapter.js

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function chapter(result, lines, index) {
2525
continue;
2626
}
2727
inCodeBlock = !inCodeBlock;
28-
case inCodeBlock:
2928
continue;
3029
case !!Match.page(line):
3130
return page_1.page(result, lines.slice(i), index);

Diff for: lib/build/parser/match.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2+
var cleanup_1 = require('./cleanup');
23
function match(char, times) {
34
return new RegExp('^' + char + '{' + times + '}(?!#)(.*?)$', 'gm');
45
}
@@ -10,15 +11,15 @@ var regex = {
1011
'```': match('`', 3),
1112
'action': /^@(action|test|hint|continue)/,
1213
'import': /^@import\((.+)\)$/,
13-
'continue': /^@continue/
14+
'onComplete': /^@onComplete\((.+)\)$/
1415
};
1516
function parseWithCode(code) {
1617
return function (line) {
1718
if (!line) {
1819
return null;
1920
}
2021
if (line.match(regex[code])) {
21-
return regex[code].exec(line)[1];
22+
return cleanup_1.trimQuotes(regex[code].exec(line)[1]);
2223
}
2324
else {
2425
return null;
@@ -32,7 +33,7 @@ exports.task = parseWithCode('+');
3233
exports.codeBlock = parseWithCode('```');
3334
exports.isAction = parseWithCode('action');
3435
exports.isImport = parseWithCode('import');
35-
exports.isContinue = parseWithCode('continue');
36+
exports.isComplete = parseWithCode('onComplete');
3637
exports.isArray = function (line) {
3738
var isMatch = line.match(/^\[.+\]$/);
3839
return isMatch ? isMatch[0] : null;

Diff for: lib/build/parser/page.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ var task_1 = require('./task');
55
var import_1 = require('./import');
66
var cleanup_1 = require('./cleanup');
77
function page(result, lines, index) {
8-
var hasBreak = null;
98
index.page += 1;
109
index.task = -1;
1110
result.chapters[index.chapter].pages.push({
1211
title: Match.page(lines[0]).trim(),
1312
description: ''
1413
});
1514
var inCodeBlock = false;
16-
var currentContinue = null;
15+
var currentComplete = null;
1716
var bracketCount = 0;
1817
var i = 0;
1918
while (i < lines.length - 1) {
@@ -26,19 +25,20 @@ function page(result, lines, index) {
2625
case !!Match.codeBlock(line):
2726
if (line.length > 3) {
2827
result.chapters[index.chapter].pages[index.page].description += '\n' + line;
29-
continue;
3028
}
31-
inCodeBlock = !inCodeBlock;
29+
else {
30+
inCodeBlock = !inCodeBlock;
31+
}
32+
continue;
3233
case inCodeBlock:
3334
continue;
34-
case !!Match.isContinue(line) || !!currentContinue:
35-
currentContinue = currentContinue ? currentContinue += line : line;
35+
case !!Match.isComplete(line) || !!currentComplete:
36+
currentComplete = currentComplete ? currentComplete += line : Match.isComplete(line);
3637
bracketCount = cleanup_1.bracketTracker(line);
3738
if (bracketCount === 0) {
38-
result.chapters[index.chapter].pages[index.page].continue = currentContinue;
39-
currentContinue = null;
39+
result.chapters[index.chapter].pages[index.page].onComplete = currentComplete;
40+
currentComplete = null;
4041
}
41-
console.log(line);
4242
continue;
4343
case !!Match.chapter(line):
4444
return chapter_1.chapter(result, lines.slice(i), index);

Diff for: lib/build/parser/project.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ function project(result, lines, index) {
1515
case !!Match.codeBlock(line):
1616
if (line.length > 3) {
1717
result.project.description += line;
18-
continue;
1918
}
20-
inCodeBlock = !inCodeBlock;
21-
case inCodeBlock:
19+
else {
20+
inCodeBlock = !inCodeBlock;
21+
}
2222
continue;
2323
case !!Match.project(line):
2424
result.project.title = Match.project(line).trim();

Diff for: lib/list/list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22
var chalk = require('chalk');
33
function tutorials() {
4-
console.log("List of tutorial packages...");
4+
console.log('List of tutorial packages...');
55
console.log(chalk.red('"Tutorials" feature not implemented yet.'));
66
}
77
exports.tutorials = tutorials;

Diff for: lib/publish/validate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var file_1 = require('../tools/file');
55
function incrementVersion(version) {
66
var finalDot = version.lastIndexOf('.');
77
var start = version.substring(0, finalDot + 1);
8-
var patch = parseInt(version.substring(finalDot + 1, version.length)) + 1;
8+
var patch = parseInt(version.substring(finalDot + 1, version.length), 10) + 1;
99
return start + patch;
1010
}
1111
function versionIsGreaterThanCurrent(version) {
@@ -14,7 +14,7 @@ function versionIsGreaterThanCurrent(version) {
1414
process.exit(1);
1515
}
1616
var currentVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
17-
if (parseInt(version) <= parseInt(currentVersion)) {
17+
if (parseInt(version, 10) <= parseInt(currentVersion, 10)) {
1818
console.log(chalk.yellow("\n Published version is not larger than current version.\n Current: \"" + currentVersion + "\"\n > coderoad publish \"" + incrementVersion(currentVersion) + "\"\n "));
1919
process.exit(1);
2020
}

Diff for: src/build/build.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function build(lines: string[]): CR.Output {
1111
description: ''
1212
},
1313
chapters: []
14-
}
14+
};
1515
let index = {
1616
chapter: -1,
1717
page: -1,
@@ -33,8 +33,5 @@ export default function(filePath: string, output = './coderoad.json'): void {
3333
// Safe to Write coderoad.json
3434
fs.writeFileSync(output, result, 'utf8');
3535
}
36-
3736
createReadme();
38-
39-
4037
}

Diff for: src/build/parser/actions.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ function doAction(type: CR.OutputAction, isArray, actionValue, result, line, ind
2020
valueList.forEach((value) => {
2121
value = trimQuotes(value.trim(), true);
2222
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(value);
23-
})
23+
});
2424
} else {
2525
result.chapters[index.chapter].pages[index.page].tasks[index.task][type].push(actionValue);
2626
}
2727
return result;
2828
}
2929

3030
export function addToTasks(result, line, index) {
31-
let action: CR.TaskAction|string = Match.isAction(line); //: 'action'|'test'|'hint'|'continue'
31+
let action: CR.TaskAction|string = Match.isAction(line); // 'action'|'test'|'hint'|'continue'
3232
let task: CR.Task = result.chapters[index.chapter].pages[index.page].tasks[index.task];
3333
let trimmedContent: string = line.slice(action.length + 2, line.length - 1); // content between brackets
3434
let actionValue: string = trimQuotes(trimmedContent);
@@ -41,7 +41,7 @@ export function addToTasks(result, line, index) {
4141
result = doAction('hints', isActionArray, actionValue, result, line, index);
4242
break;
4343
case 'continue':
44-
result = doAction('continue', isActionArray, actionValue, result, line, index);
44+
break;
4545
case 'action':
4646
if (task.actions === undefined) {
4747
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions = [];
@@ -52,8 +52,7 @@ export function addToTasks(result, line, index) {
5252
value = trimCommandValue(trimQuotes(value.trim()));
5353
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
5454
});
55-
}
56-
else {
55+
} else {
5756
let value: string = trimCommandValue(actionValue);
5857
result.chapters[index.chapter].pages[index.page].tasks[index.task].actions.push(value);
5958
}

Diff for: src/build/parser/chapter.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Match from './match';
22
import {page} from './page';
33
import {loadImport} from './import';
4-
import {trimLineBreaks} from './cleanup';
54

65
export function chapter(result: CR.Output, lines: string[], index: CR.Index): CR.Output {
76
index.page = -1;
@@ -31,7 +30,6 @@ export function chapter(result: CR.Output, lines: string[], index: CR.Index): CR
3130
continue;
3231
}
3332
inCodeBlock = !inCodeBlock;
34-
case inCodeBlock:
3533
continue;
3634

3735
// ###

Diff for: src/build/parser/cleanup.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function trimQuotes(text: string, quotesOnly?: boolean): string {
1717
if (!!text.match(/^[\r\n]/)) {
1818
return text;
1919
} else if (!!text.match(/^\s/)) {
20-
return trimQuotes(text.slice(1), quotesOnly)
20+
return trimQuotes(text.slice(1), quotesOnly);
2121
} else if (!!text.match(/\s$/)) {
2222
// trim trailing spaces
2323
return trimQuotes(text.slice(0, text.length - 1), quotesOnly);

Diff for: src/build/parser/match.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {trimQuotes} from './cleanup';
2+
13
function match(char: string, times: number) {
24
return new RegExp('^' + char + '{' + times + '}(?!#)(.*?)$', 'gm');
35
}
@@ -10,7 +12,7 @@ var regex = {
1012
'```': match('`', 3),
1113
'action': /^@(action|test|hint|continue)/,
1214
'import': /^@import\((.+)\)$/,
13-
'continue': /^@continue/
15+
'onComplete': /^@onComplete\((.+)\)$/
1416
};
1517

1618
function parseWithCode(code: string) {
@@ -19,7 +21,7 @@ function parseWithCode(code: string) {
1921
return null;
2022
}
2123
if (line.match(regex[code])) {
22-
return regex[code].exec(line)[1];
24+
return trimQuotes(regex[code].exec(line)[1]);
2325
} else {
2426
return null;
2527
}
@@ -33,12 +35,12 @@ export const task = parseWithCode('+');
3335
export const codeBlock = parseWithCode('```');
3436
export const isAction = parseWithCode('action');
3537
export const isImport = parseWithCode('import');
36-
export const isContinue = parseWithCode('continue');
38+
export const isComplete = parseWithCode('onComplete');
3739

3840
export const isArray = function(line: string): string {
3941
let isMatch = line.match(/^\[.+\]$/);
4042
return isMatch ? isMatch[0] : null;
41-
}
43+
};
4244

4345
export function isEmpty(line: string): boolean {
4446
return !line.length || !!line.match(/^\s+?[\n\r]/);

Diff for: src/build/parser/page.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import {loadImport} from './import';
55
import {bracketTracker} from './cleanup';
66

77
export function page(result: CR.Output, lines: string[], index: CR.Index): CR.Output {
8-
let hasBreak: number = null;
98
index.page += 1;
109
index.task = -1;
1110
result.chapters[index.chapter].pages.push({
1211
title: Match.page(lines[0]).trim(),
1312
description: ''
1413
});
1514
let inCodeBlock = false;
16-
let currentContinue = null;
15+
let currentComplete = null;
1716
let bracketCount = 0;
1817

1918
let i = 0;
@@ -32,22 +31,22 @@ export function page(result: CR.Output, lines: string[], index: CR.Index): CR.Ou
3231
case !!Match.codeBlock(line):
3332
if (line.length > 3) {
3433
result.chapters[index.chapter].pages[index.page].description += '\n' + line;
35-
continue;
34+
} else {
35+
inCodeBlock = !inCodeBlock;
3636
}
37-
inCodeBlock = !inCodeBlock;
37+
continue;
3838
case inCodeBlock:
3939
continue;
4040

41-
// @continue
42-
case !!Match.isContinue(line) || !!currentContinue:
43-
currentContinue = currentContinue ? currentContinue += line : line;
41+
// @onComplete
42+
case !!Match.isComplete(line) || !!currentComplete:
43+
currentComplete = currentComplete ? currentComplete += line : Match.isComplete(line);
4444
bracketCount = bracketTracker(line);
45+
// complete
4546
if (bracketCount === 0) {
46-
// if continue()
47-
result.chapters[index.chapter].pages[index.page].continue = currentContinue;
48-
currentContinue = null;
47+
result.chapters[index.chapter].pages[index.page].onComplete = currentComplete;
48+
currentComplete = null;
4949
}
50-
console.log(line);
5150
continue;
5251

5352
// ##

Diff for: src/build/parser/project.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Match from './match';
22
import {chapter} from './chapter';
33
import {loadImport} from './import';
4-
import {trimLineBreaks} from './cleanup';
54

65
export function project(result: CR.Output, lines: string[], index: CR.Index): CR.Output {
76
let inCodeBlock = false;
@@ -22,10 +21,9 @@ export function project(result: CR.Output, lines: string[], index: CR.Index): CR
2221
case !!Match.codeBlock(line):
2322
if (line.length > 3) {
2423
result.project.description += line;
25-
continue;
24+
} else {
25+
inCodeBlock = !inCodeBlock;
2626
}
27-
inCodeBlock = !inCodeBlock;
28-
case inCodeBlock:
2927
continue;
3028

3129
// #

Diff for: src/build/readme.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function generateReadme(data: CR.Output, packageJson: PackageJson): string {
8383

8484
chapters.forEach(function(chapter) {
8585
readme = readme.concat(chapter);
86-
})
86+
});
8787
}
8888

8989
return readme.join('\n');

Diff for: src/create/create.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as fs from 'fs';
21
import {validatePackageName} from './validate';
32
import {createPackageJson, createTutorialMd, createTestFiles} from './write-demo';
43
import {createReadme} from '../build/readme';

Diff for: src/create/write-demo.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
3-
import * as prompt from 'prompt';
43
import {fileExists} from '../tools/file';
54

65
function createFile(pathToFile: string): void {
@@ -33,13 +32,13 @@ export function createPackageJson(name: string): void {
3332
if (!fileExists('package.json')) {
3433
let inputPath = path.join(__dirname, '..', '..', 'setup', 'package.json');
3534
let packageJson = JSON.parse(fs.readFileSync(inputPath, 'utf8'));
36-
packageJson.name = 'coderoad-' + name
35+
packageJson.name = 'coderoad-' + name;
3736
let packageJsonString = JSON.stringify(packageJson, null, 2);
3837
fs.writeFileSync('package.json', packageJsonString, 'utf8');
3938
}
4039
}
4140

42-
export function createTestFiles():void {
41+
export function createTestFiles(): void {
4342
createFile(path.join('tutorial', '1', '01', '01.spec.js'));
4443
createFile(path.join('tutorial', '1', '01', '02.spec.js'));
4544
createFile(path.join('tutorial', '1', '02', '01.spec.js'));

Diff for: src/list/list.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const chalk = require('chalk');
22

3-
export function tutorials():void {
4-
console.log("List of tutorial packages...");
3+
export function tutorials(): void {
4+
console.log('List of tutorial packages...');
55
console.log(chalk.red('"Tutorials" feature not implemented yet.'));
66
}

Diff for: src/publish/validate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {fileExists} from '../tools/file';
66
function incrementVersion(version: string): string {
77
let finalDot = version.lastIndexOf('.');
88
let start = version.substring(0, finalDot + 1);
9-
let patch = parseInt(version.substring(finalDot + 1, version.length)) + 1;
9+
let patch = parseInt(version.substring(finalDot + 1, version.length), 10) + 1;
1010
return start + patch;
1111
}
1212

@@ -20,7 +20,7 @@ function versionIsGreaterThanCurrent(version: string): void {
2020
}
2121

2222
let currentVersion: string = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
23-
if (parseInt(version) <= parseInt(currentVersion)) {
23+
if (parseInt(version, 10) <= parseInt(currentVersion, 10)) {
2424
console.log(chalk.yellow(`
2525
Published version is not larger than current version.
2626
Current: "${currentVersion}"

Diff for: src/search/search.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import * as fs from 'fs';
21
import * as chalk from 'chalk';
32
import {validateQuery} from './validate';
4-
import {exec} from 'child_process';
53

64
export default function search(query: string): void {
75
validateQuery(query);

0 commit comments

Comments
 (0)