From c182bbdd7778a130b43bd6148e53414600642594 Mon Sep 17 00:00:00 2001 From: Sam Verschueren Date: Fri, 29 Sep 2017 11:18:57 +0200 Subject: [PATCH] Tweaks (#22) --- .gitignore | 1 + .npmrc | 1 + .travis.yml | 1 + index.js | 20 +++++++++----------- package.json | 3 --- 5 files changed, 12 insertions(+), 14 deletions(-) create mode 100644 .npmrc diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index b18bae5..57505cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ sudo: false language: node_js node_js: + - '8' - '6' - '4' diff --git a/index.js b/index.js index eda0b1b..b2359aa 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ 'use strict'; -// detect either spaces or tabs but not both to properly handle tabs -// for indentation and spaces for alignment +// Detect either spaces or tabs but not both to properly handle tabs for indentation and spaces for alignment const INDENT_RE = /^(?:( )+|\t+)/; function getMostUsed(indents) { @@ -32,15 +31,14 @@ module.exports = str => { throw new TypeError('Expected a string'); } - // used to see if tabs or spaces are the most used + // Used to see if tabs or spaces are the most used let tabs = 0; let spaces = 0; - // remember the size of previous line's indentation + // Remember the size of previous line's indentation let prev = 0; - // remember how many indents/unindents as occurred for a given size - // and how much lines follow a given indentation + // Remember how many indents/unindents as occurred for a given size and how much lines follow a given indentation // // indents = { // 3: [1, 0], @@ -50,15 +48,15 @@ module.exports = str => { // } const indents = new Map(); - // pointer to the array of last used indent + // Pointer to the array of last used indent let current; - // whether the last action was an indent (opposed to an unindent) + // Whether the last action was an indent (opposed to an unindent) let isIndent; for (const line of str.split(/\n/g)) { if (!line) { - // ignore empty lines + // Ignore empty lines continue; } @@ -81,7 +79,7 @@ module.exports = str => { prev = indent; if (diff) { - // an indent or unindent has been detected + // An indent or unindent has been detected isIndent = diff > 0; @@ -94,7 +92,7 @@ module.exports = str => { indents.set(diff, current); } } else if (current) { - // if the last action was an indent, increment the weight + // If the last action was an indent, increment the weight current[1] += Number(isIndent); } } diff --git a/package.json b/package.json index 81c7edf..0ba6438 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,5 @@ "devDependencies": { "ava": "*", "xo": "*" - }, - "xo": { - "esnext": true } }