Skip to content

Commit

Permalink
Some tweaks to the TS make file
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jan 23, 2017
1 parent 82acc59 commit 83937bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -170,6 +170,7 @@
"git-branch": "^0.3.0",
"has-ansi": "^2.0.0",
"inquirer": "^2.0.0",
"is-array-sorted": "^1.0.0",
"lolex": "^1.4.0",
"mkdirp": "^0.5.1",
"nyc": "^10.0.0",
Expand Down
20 changes: 5 additions & 15 deletions types/make.js
Expand Up @@ -14,9 +14,10 @@

const path = require('path');
const fs = require('fs');
const isArraySorted = require('is-array-sorted');
const runner = require('../lib/runner');

const arrayHas = parts => part => parts.indexOf(part) > -1;
const arrayHas = parts => part => parts.indexOf(part) !== -1;

const base = fs.readFileSync(path.join(__dirname, 'base.d.ts'), 'utf8');

Expand All @@ -35,13 +36,13 @@ function generatePrefixed(prefix) {
for (const part of allParts) {
const parts = prefix.concat([part]);

if (prefix.indexOf(part) > -1 || !verify(parts, true)) {
if (prefix.indexOf(part) !== -1 || !verify(parts, true)) {
// Function already in prefix or not allowed here
continue;
}

// If `parts` is not sorted, we alias it to the sorted chain
if (!isSorted(parts)) {
if (!isArraySorted(parts)) {
const chain = parts.sort().join('.');

if (exists(parts)) {
Expand All @@ -55,7 +56,7 @@ function generatePrefixed(prefix) {
// `always` is a valid prefix, for instance of `always.after`,
// but not a valid function name.
if (verify(parts, false)) {
if (parts.indexOf('todo') > -1) {
if (parts.indexOf('todo') !== -1) { // eslint-disable-line no-negated-condition
output += '\t' + writeFunction(part, 'name: string', 'void');
} else {
const type = testType(parts);
Expand Down Expand Up @@ -147,17 +148,6 @@ function exists(parts) {
return false;
}

// Checks that an array is sorted
function isSorted(a) {
for (let i = 1; i < a.length; i++) {
if (a[i - 1] >= a[i]) {
return false;
}
}

return true;
}

// Returns the type name of for the test implementation
function testType(parts) {
const has = arrayHas(parts);
Expand Down

0 comments on commit 83937bf

Please sign in to comment.