├── .babelrc ├── .gitignore ├── .travis.yml ├── test ├── globals.js └── src │ ├── template-tag.js │ ├── chain-options.js │ └── index.js ├── .eslintrc-node.yaml ├── .eslintrc-mocha.yaml ├── .eslintrc-es2015.yaml ├── src ├── template-tag.js ├── chain-options.js └── index.js ├── eslint ├── eslint-node-commonjs.yaml ├── eslint-es2015.yaml └── eslint-defaults.yaml ├── LICENSE-MIT ├── package.json ├── examples └── examples.js ├── README.md └── Gruntfile.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | npm-debug.log* 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4.2" 4 | sudo: false 5 | -------------------------------------------------------------------------------- /test/globals.js: -------------------------------------------------------------------------------- 1 | import {assert, expect} from 'chai'; 2 | 3 | global.assert = assert; 4 | global.expect = expect; 5 | -------------------------------------------------------------------------------- /.eslintrc-node.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: 3 | - "./eslint/eslint-defaults.yaml" 4 | - "./eslint/eslint-node-commonjs.yaml" 5 | -------------------------------------------------------------------------------- /.eslintrc-mocha.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | env: 3 | mocha: true 4 | globals: 5 | assert: true 6 | expect: true 7 | extends: 8 | - ".eslintrc-es2015.yaml" 9 | -------------------------------------------------------------------------------- /.eslintrc-es2015.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | extends: 3 | - "./eslint/eslint-defaults.yaml" 4 | - "./eslint/eslint-node-commonjs.yaml" 5 | - "./eslint/eslint-es2015.yaml" 6 | -------------------------------------------------------------------------------- /src/template-tag.js: -------------------------------------------------------------------------------- 1 | export default function(strings, ...values) { 2 | return strings.reduce((result, string, n) => result + (n > 0 ? values[n - 1] : '') + string, ''); 3 | } 4 | -------------------------------------------------------------------------------- /eslint/eslint-node-commonjs.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | env: 3 | node: true 4 | 5 | ecmaFeatures: 6 | blockBindings: true 7 | 8 | rules: 9 | 10 | # General but applicable here 11 | 12 | strict: 13 | - 2 14 | - global 15 | 16 | # Node.js and CommonJS 17 | 18 | callback-return: 19 | - 2 20 | - [ callback, cb, done, next ] 21 | handle-callback-err: 22 | - 2 23 | - "^err(?:or)?$" 24 | no-mixed-requires: 0 25 | no-new-require: 2 26 | no-path-concat: 2 27 | no-process-exit: 2 28 | no-restricted-modules: 0 29 | no-sync: 0 30 | -------------------------------------------------------------------------------- /src/chain-options.js: -------------------------------------------------------------------------------- 1 | export default function(props, fn) { 2 | function getWrapper(options = {}) { 3 | const wrapper = (...args) => fn(options, ...args); 4 | props.forEach(prop => { 5 | Object.defineProperty(wrapper, prop, { 6 | enumerable: true, 7 | get() { 8 | return getWrapper(Object.assign({}, options, {[prop]: !options[prop]})); 9 | }, 10 | set() {}, 11 | }); 12 | wrapper[prop] = (...args) => wrapper(...args); 13 | }); 14 | return wrapper; 15 | } 16 | return getWrapper(); 17 | } 18 | -------------------------------------------------------------------------------- /eslint/eslint-es2015.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | ecmaFeatures: 3 | modules: true 4 | 5 | env: 6 | es6: true 7 | 8 | rules: 9 | # General but applicable here 10 | 11 | no-inner-declarations: 0 12 | no-iterator: 0 13 | 14 | # ECMAScript 6 15 | 16 | arrow-parens: 17 | - 2 18 | - as-needed 19 | arrow-spacing: 20 | - 2 21 | - before: true 22 | after: true 23 | constructor-super: 2 24 | generator-star-spacing: 25 | - 2 26 | - before 27 | no-class-assign: 2 28 | no-const-assign: 2 29 | no-this-before-super: 2 30 | no-var: 2 31 | object-shorthand: 32 | - 2 33 | - always 34 | prefer-const: 2 35 | prefer-spread: 2 36 | prefer-reflect: 0 37 | require-yield: 2 38 | -------------------------------------------------------------------------------- /test/src/template-tag.js: -------------------------------------------------------------------------------- 1 | import templateTag from '../../src/template-tag'; 2 | 3 | describe('templateTag', function() { 4 | 5 | it('should behave like no tag was specified', function() { 6 | expect(templateTag`foo bar`).to.equal(`foo bar`); 7 | expect(templateTag`${1}`).to.equal(`${1}`); 8 | expect(templateTag`${1}${2}`).to.equal(`${1}${2}`); 9 | expect(templateTag`${1} bar`).to.equal(`${1} bar`); 10 | expect(templateTag`foo ${1}`).to.equal(`foo ${1}`); 11 | expect(templateTag`foo ${1} bar`).to.equal(`foo ${1} bar`); 12 | expect(templateTag`${1} foo bar`).to.equal(`${1} foo bar`); 13 | expect(templateTag`foo bar ${1}`).to.equal(`foo bar ${1}`); 14 | expect(templateTag`${1} foo ${2} bar ${3}`).to.equal(`${1} foo ${2} bar ${3}`); 15 | }); 16 | 17 | }); 18 | -------------------------------------------------------------------------------- /test/src/chain-options.js: -------------------------------------------------------------------------------- 1 | import chainOptions from '../../src/chain-options'; 2 | 3 | describe('chainOptions', function() { 4 | 5 | it('should chain and pass args correctly', function() { 6 | let args; 7 | const fn = chainOptions(['foo', 'bar'], function(options, ...a) { 8 | expect(a).to.deep.equal(args); 9 | return options; 10 | }); 11 | args = []; 12 | expect(fn()).to.deep.equal({}); 13 | args = ['foo', 123, true, null]; 14 | expect(fn(...args)).to.deep.equal({}); 15 | expect(fn.foo(...args)).to.deep.equal({foo: true}); 16 | expect(fn.bar(...args)).to.deep.equal({bar: true}); 17 | expect(fn.foo.bar(...args)).to.deep.equal({foo: true, bar: true}); 18 | expect(fn.bar.foo(...args)).to.deep.equal({foo: true, bar: true}); 19 | expect(fn.foo.foo(...args)).to.deep.equal({foo: false}); 20 | expect(fn.foo.bar.foo(...args)).to.deep.equal({foo: false, bar: true}); 21 | }); 22 | 23 | }); 24 | 25 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 "Cowboy" Ben Alman 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "heredoc-tag", 3 | "description": "Heredoc helpers for ES2015 template strings", 4 | "version": "0.1.0", 5 | "author": "\"Cowboy\" Ben Alman (http://benalman.com/)", 6 | "homepage": "https:/github.com/cowboy/node-heredoc-tag", 7 | "repository": "cowboy/node-heredoc-tag", 8 | "license": "MIT", 9 | "main": "build/index", 10 | "files": [ 11 | "build" 12 | ], 13 | "keywords": [ 14 | "es2015", 15 | "es6", 16 | "heredoc", 17 | "template", 18 | "string" 19 | ], 20 | "scripts": { 21 | "build": "grunt build", 22 | "test": "grunt test" 23 | }, 24 | "dependencies": { 25 | "babel-plugin-transform-runtime": "^6.4.0" 26 | }, 27 | "devDependencies": { 28 | "babel-preset-es2015": "^6.3.13", 29 | "babel-register": "^6.4.3", 30 | "chai": "^3.4.1", 31 | "grunt": "^0.4.5", 32 | "grunt-babel": "^6.0.0", 33 | "grunt-cli": "^0.1.13", 34 | "grunt-contrib-clean": "^0.7.0", 35 | "grunt-contrib-watch": "^0.6.1", 36 | "grunt-eslint": "^17.3.1", 37 | "grunt-mocha-test": "^0.12.7", 38 | "mocha": "^2.3.4", 39 | "source-map-support": "^0.4.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import chainOptions from './chain-options'; 2 | import templateTag from './template-tag'; 3 | 4 | export default chainOptions(['trim', 'unindent', 'oneline'], function({trim, unindent, oneline}, strings, ...values) { 5 | let str = templateTag(strings, ...values); 6 | let lines = str.split('\n'); 7 | 8 | if (oneline) { 9 | if (trim) { 10 | // Remove any whitespace-only lines. 11 | lines = lines.filter(s => /\S/.test(s)); 12 | // Trim each line individually. 13 | lines = lines.map(s => s.trim()); 14 | // Join all trimmed lines on space. 15 | str = lines.join(' '); 16 | } 17 | else { 18 | // Just remove newlines. 19 | str = str.replace(/\n+/g, ''); 20 | } 21 | } 22 | 23 | else if (unindent) { 24 | // Unindent every line by the minimum indent shared by all non-whitespace lines. 25 | const indent = lines.filter(s => /\S/.test(s)).reduce((n, s) => Math.min(n, s.match(/^\s*/)[0].length), Infinity); 26 | lines = lines.map(s => s.slice(indent)); 27 | if (trim) { 28 | // Remove all trailing whitespace. 29 | lines = lines.map(s => s.replace(/\s+$/, '')); 30 | // Join string and remove leading/trailing newlines. 31 | str = lines.join('\n').replace(/^\n+|\n+$/g, ''); 32 | } 33 | else { 34 | str = lines.join('\n'); 35 | } 36 | } 37 | 38 | else if (trim) { 39 | str = str.trim(); 40 | } 41 | 42 | return str; 43 | }); 44 | -------------------------------------------------------------------------------- /examples/examples.js: -------------------------------------------------------------------------------- 1 | // Run these examples with: node -r babel-register examples.js 2 | 3 | import heredoc from '../'; 4 | 5 | let str; 6 | 7 | 8 | // Trim 9 | str = heredoc.trim` 10 | 11 | this is a test 12 | 13 | `; 14 | console.log(`"${str}"`); // "this is a test" 15 | 16 | 17 | // Remove newlines 18 | str = heredoc.oneline` 19 | Here is a sentence 20 | split across 21 | multiple lines. 22 | `; 23 | console.log(`"${str}"`); // " Here is a sentence split across multiple lines." 24 | 25 | 26 | // Remove newlines, trim each line, then join lines with a space 27 | str = heredoc.oneline.trim` 28 | Here is a sentence 29 | split across 30 | multiple lines. 31 | `; 32 | console.log(`"${str}"`); // "Here is a sentence split across multiple lines." 33 | 34 | 35 | // Unindent as far as possible 36 | str = heredoc.unindent` 37 | This is an example 38 | where some text is indented more 39 | and some text is indented less 40 | for whatever reason. 41 | `; 42 | console.log(`"${str}"`); 43 | // " 44 | // This is an example 45 | // where some text is indented more 46 | // and some text is indented less 47 | // for whatever reason. 48 | // " 49 | 50 | 51 | // Unindent, trim the ends of lines, trim leading/trailing whitespace 52 | str = heredoc.unindent.trim` 53 | This is an example 54 | where some text is indented more 55 | and some text is indented less 56 | for whatever reason. 57 | `; 58 | console.log(`"${str}"`); 59 | // " This is an example 60 | // where some text is indented more 61 | // and some text is indented less 62 | // for whatever reason." 63 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # heredoc-tag 2 | 3 | > Heredoc helpers for ES2015 template strings 4 | 5 | [![Build Status](https://travis-ci.org/cowboy/node-heredoc-tag.svg?branch=master)](https://travis-ci.org/cowboy/node-heredoc-tag) 6 | [![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) 7 | 8 | ## Installation 9 | 10 | ``` 11 | npm install heredoc-tag 12 | ``` 13 | 14 | ## Examples 15 | 16 | _(Taken from the [examples](examples/examples.js) file)_ 17 | 18 | ```js 19 | import heredoc from 'heredoc-tag'; 20 | let str; 21 | 22 | 23 | // Trim 24 | str = heredoc.trim` 25 | 26 | this is a test 27 | 28 | `; 29 | console.log(`"${str}"`); // "this is a test" 30 | 31 | 32 | // Remove newlines 33 | str = heredoc.oneline` 34 | Here is a sentence 35 | split across 36 | multiple lines. 37 | `; 38 | console.log(`"${str}"`); // " Here is a sentence split across multiple lines." 39 | 40 | 41 | // Remove newlines, trim each line, then join lines with a space 42 | str = heredoc.oneline.trim` 43 | Here is a sentence 44 | split across 45 | multiple lines. 46 | `; 47 | console.log(`"${str}"`); // "Here is a sentence split across multiple lines." 48 | 49 | 50 | // Unindent as far as possible 51 | str = heredoc.unindent` 52 | This is an example 53 | where some text is indented more 54 | and some text is indented less 55 | for whatever reason. 56 | `; 57 | console.log(`"${str}"`); 58 | // " 59 | // This is an example 60 | // where some text is indented more 61 | // and some text is indented less 62 | // for whatever reason. 63 | // " 64 | 65 | 66 | // Unindent, trim the ends of lines, trim leading/trailing whitespace 67 | str = heredoc.unindent.trim` 68 | This is an example 69 | where some text is indented more 70 | and some text is indented less 71 | for whatever reason. 72 | `; 73 | console.log(`"${str}"`); 74 | // " This is an example 75 | // where some text is indented more 76 | // and some text is indented less 77 | // for whatever reason." 78 | ``` 79 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('source-map-support').install(); 4 | 5 | module.exports = function(grunt) { 6 | 7 | grunt.initConfig({ 8 | babel: { 9 | options: { 10 | sourceMap: 'inline', 11 | plugins: ['transform-runtime'], 12 | }, 13 | build: { 14 | src: '**/*.js', 15 | expand: true, 16 | cwd: 'src', 17 | dest: 'build', 18 | }, 19 | }, 20 | eslint: { 21 | src: { 22 | options: { 23 | configFile: '.eslintrc-es2015.yaml', 24 | }, 25 | src: 'src/**/*.js', 26 | }, 27 | examples: { 28 | options: { 29 | configFile: '.eslintrc-es2015.yaml', 30 | }, 31 | src: 'examples/**/*.js', 32 | }, 33 | root: { 34 | options: { 35 | configFile: '.eslintrc-node.yaml', 36 | }, 37 | src: '*.js', 38 | }, 39 | test: { 40 | options: { 41 | configFile: '.eslintrc-mocha.yaml', 42 | }, 43 | src: 'test/**/*.js', 44 | }, 45 | }, 46 | clean: { 47 | build: 'build', 48 | }, 49 | mochaTest: { 50 | unit: { 51 | options: { 52 | reporter: 'spec', 53 | quiet: false, 54 | clearRequireCache: true, 55 | require: [ 56 | 'babel-register', 57 | 'test/globals', 58 | ], 59 | }, 60 | src: 'test/src/*.js', 61 | }, 62 | }, 63 | watch: { 64 | options: { 65 | spawn: false, 66 | }, 67 | src: { 68 | files: ['<%= eslint.src.src %>'], 69 | tasks: ['eslint:src', 'mochaTest', 'build'], 70 | }, 71 | root: { 72 | files: ['<%= eslint.root.src %>'], 73 | tasks: ['eslint:root'], 74 | }, 75 | test: { 76 | files: ['<%= eslint.test.src %>'], 77 | tasks: ['eslint:test', 'mochaTest'], 78 | }, 79 | lint: { 80 | options: { 81 | reload: true, 82 | }, 83 | files: ['.eslintrc*', 'eslint/*'], 84 | tasks: ['eslint'], 85 | }, 86 | }, 87 | }); 88 | 89 | grunt.registerTask('test', ['eslint', 'mochaTest']); 90 | grunt.registerTask('build', ['test', 'clean', 'babel']); 91 | grunt.registerTask('default', ['watch']); 92 | 93 | grunt.loadNpmTasks('grunt-babel'); 94 | grunt.loadNpmTasks('grunt-contrib-clean'); 95 | grunt.loadNpmTasks('grunt-contrib-watch'); 96 | grunt.loadNpmTasks('grunt-eslint'); 97 | grunt.loadNpmTasks('grunt-mocha-test'); 98 | }; 99 | -------------------------------------------------------------------------------- /test/src/index.js: -------------------------------------------------------------------------------- 1 | import heredoc from '../../src'; 2 | 3 | describe('heredoc', function() { 4 | 5 | describe('default', function() { 6 | 7 | it('should do nothing by default', function() { 8 | expect(heredoc`foo bar`).to.equal(`foo bar`); 9 | expect(heredoc`${1}`).to.equal(`${1}`); 10 | expect(heredoc`${1}${2}`).to.equal(`${1}${2}`); 11 | expect(heredoc`${1} bar`).to.equal(`${1} bar`); 12 | expect(heredoc`foo ${1}`).to.equal(`foo ${1}`); 13 | expect(heredoc`foo ${1} bar`).to.equal(`foo ${1} bar`); 14 | expect(heredoc`${1} foo bar`).to.equal(`${1} foo bar`); 15 | expect(heredoc`foo bar ${1}`).to.equal(`foo bar ${1}`); 16 | expect(heredoc`${1} foo ${2} bar ${3}`).to.equal(`${1} foo ${2} bar ${3}`); 17 | expect(heredoc` ${1} foo ${2} bar ${3} `).to.equal(` ${1} foo ${2} bar ${3} `); 18 | expect(heredoc`\n\n\n${1} foo ${2} bar ${3}\n\n\n`).to.equal(`\n\n\n${1} foo ${2} bar ${3}\n\n\n`); 19 | expect(heredoc`\n \n${1} foo ${2} bar ${3}\n \n`).to.equal(`\n \n${1} foo ${2} bar ${3}\n \n`); 20 | }); 21 | 22 | it('should trim', function() { 23 | expect(heredoc.trim` foo `).to.equal(`foo`); 24 | expect(heredoc.trim` \n foo \n`).to.equal(`foo`); 25 | expect(heredoc.trim`\n \n foo \n \n`).to.equal(`foo`); 26 | expect(heredoc.trim` ${1} `).to.equal(`${1}`); 27 | expect(heredoc.trim` \n ${1} \n `).to.equal(`${1}`); 28 | expect(heredoc.trim`\n \n ${1} \n \n`).to.equal(`${1}`); 29 | }); 30 | 31 | it('should remove newlines', function() { 32 | expect(heredoc.oneline` foo `).to.equal(` foo `); 33 | expect(heredoc.oneline` \n foo \n `).to.equal(` foo `); 34 | expect(heredoc.oneline`\n \n foo \n \n`).to.equal(` foo `); 35 | expect(heredoc.oneline` ${1} `).to.equal(` ${1} `); 36 | expect(heredoc.oneline` \n ${1} \n `).to.equal(` ${1} `); 37 | expect(heredoc.oneline`\n \n ${1} \n \n`).to.equal(` ${1} `); 38 | }); 39 | 40 | it('should remove newlines, trim each line, then join lines with a space', function() { 41 | expect(heredoc.oneline.trim` foo `).to.equal(`foo`); 42 | expect(heredoc.oneline.trim` \n foo \n `).to.equal(`foo`); 43 | expect(heredoc.oneline.trim`\n \n foo \n \n`).to.equal(`foo`); 44 | expect(heredoc.oneline.trim` ${1} `).to.equal(`${1}`); 45 | expect(heredoc.oneline.trim` \n ${1} \n `).to.equal(`${1}`); 46 | expect(heredoc.oneline.trim`\n \n ${1} \n \n`).to.equal(`${1}`); 47 | expect(heredoc.oneline.trim`\n foo \n bar \n baz \n`).to.equal(`foo bar baz`); 48 | expect(heredoc.oneline.trim`\n foo bar \n \n baz \n`).to.equal(`foo bar baz`); 49 | }); 50 | 51 | it('should unindent as far as possible', function() { 52 | expect(heredoc.unindent` foo`).to.equal(`foo`); 53 | expect(heredoc.unindent` foo `).to.equal(`foo `); 54 | expect(heredoc.unindent` foo\n bar`).to.equal(`foo\nbar`); 55 | expect(heredoc.unindent` foo \n bar `).to.equal(`foo \nbar `); 56 | expect(heredoc.unindent`\n\n foo \n bar \n\n`).to.equal(`\n\nfoo \nbar \n\n`); 57 | expect(heredoc.unindent` foo\n bar\n baz`).to.equal(`foo\nbar\n baz`); 58 | expect(heredoc.unindent` foo\n bar\n baz`).to.equal(` foo\nbar\n baz`); 59 | expect(heredoc.unindent` foo\n bar\n baz`).to.equal(`foo\nbar\nbaz`); 60 | expect(heredoc.unindent` foo\n bar\nbaz`).to.equal(` foo\n bar\nbaz`); 61 | expect(heredoc.unindent` \n \n foo\n bar \nbaz \n \n`).to.equal(` \n \n foo\n bar \nbaz \n \n`); 62 | expect(heredoc.unindent` \n \n foo\n bar \n baz \n \n`).to.equal(`\n\n foo\nbar \nbaz \n\n`); 63 | }); 64 | 65 | it('should unindent, trim the ends of lines, trim leading/trailing whitespace', function() { 66 | expect(heredoc.unindent.trim` foo`).to.equal(`foo`); 67 | expect(heredoc.unindent.trim` foo `).to.equal(`foo`); 68 | expect(heredoc.unindent.trim` foo\n bar`).to.equal(`foo\nbar`); 69 | expect(heredoc.unindent.trim` foo \n bar `).to.equal(`foo\nbar`); 70 | expect(heredoc.unindent.trim`\n\n foo \n bar \n\n`).to.equal(`foo\nbar`); 71 | expect(heredoc.unindent.trim` foo\n bar\n baz`).to.equal(`foo\nbar\n baz`); 72 | expect(heredoc.unindent.trim` foo\n bar\n baz`).to.equal(` foo\nbar\n baz`); 73 | expect(heredoc.unindent.trim` foo\n bar\n baz`).to.equal(`foo\nbar\nbaz`); 74 | expect(heredoc.unindent.trim` foo\n bar\nbaz`).to.equal(` foo\n bar\nbaz`); 75 | expect(heredoc.unindent.trim` \n \n foo\n bar \nbaz \n \n`).to.equal(` foo\n bar\nbaz`); 76 | expect(heredoc.unindent.trim` \n \n foo\n bar \n baz \n \n`).to.equal(` foo\nbar\nbaz`); 77 | }); 78 | 79 | }); 80 | 81 | }); 82 | 83 | -------------------------------------------------------------------------------- /eslint/eslint-defaults.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | rules: 3 | 4 | # Possible Errors 5 | 6 | comma-dangle: 7 | - 2 8 | - always-multiline 9 | no-cond-assign: 10 | - 2 11 | - except-parens 12 | no-console: 0 13 | no-constant-condition: 1 14 | no-control-regex: 2 15 | no-debugger: 1 16 | no-dupe-args: 2 17 | no-dupe-keys: 2 18 | no-duplicate-case: 2 19 | no-empty-character-class: 2 20 | no-empty: 1 21 | no-ex-assign: 2 22 | no-extra-boolean-cast: 2 23 | no-extra-parens: 24 | - 2 25 | - functions 26 | no-extra-semi: 2 27 | no-func-assign: 2 28 | no-inner-declarations: 2 29 | no-invalid-regexp: 2 30 | no-irregular-whitespace: 2 31 | no-negated-in-lhs: 2 32 | no-obj-calls: 2 33 | no-regex-spaces: 2 34 | no-sparse-arrays: 2 35 | no-unreachable: 1 36 | use-isnan: 2 37 | valid-jsdoc: 38 | - 2 39 | - prefer: 40 | return: returns 41 | valid-typeof: 2 42 | no-unexpected-multiline: 2 43 | 44 | # Best Practices 45 | 46 | accessor-pairs: 2 47 | block-scoped-var: 2 48 | complexity: 0 49 | consistent-return: 2 50 | curly: 51 | - 2 52 | - all 53 | default-case: 2 54 | dot-notation: 2 55 | dot-location: 56 | - 2 57 | - property 58 | eqeqeq: 59 | - 2 60 | - "allow-null" 61 | guard-for-in: 0 62 | no-alert: 2 63 | no-caller: 2 64 | no-div-regex: 0 65 | no-else-return: 2 66 | no-empty-label: 2 67 | no-eq-null: 0 68 | no-eval: 2 69 | no-extend-native: 0 70 | no-extra-bind: 2 71 | no-fallthrough: 2 72 | no-floating-decimal: 2 73 | no-implicit-coercion: 2 74 | no-implied-eval: 2 75 | no-invalid-this: 0 76 | no-iterator: 2 77 | no-labels: 0 78 | no-lone-blocks: 2 79 | no-loop-func: 2 80 | no-multi-spaces: 2 81 | no-multi-str: 2 82 | no-native-reassign: 2 83 | no-new-func: 0 84 | no-new-wrappers: 2 85 | no-new: 2 86 | no-octal-escape: 2 87 | no-octal: 2 88 | no-param-reassign: 0 89 | no-process-env: 0 90 | no-proto: 2 91 | no-redeclare: 92 | - 2 93 | - builtinGlobals: false 94 | no-return-assign: 2 95 | no-script-url: 2 96 | no-self-compare: 2 97 | no-sequences: 2 98 | no-throw-literal: 2 99 | no-unused-expressions: 2 100 | no-useless-call: 2 101 | no-void: 2 102 | no-warning-comments: 1 103 | no-with: 2 104 | radix: 2 105 | vars-on-top: 0 106 | wrap-iife: 107 | - 2 108 | - inside 109 | yoda: 110 | - 2 111 | - never 112 | 113 | # Strict Mode 114 | 115 | strict: 116 | - 2 117 | - function 118 | 119 | # Variables 120 | 121 | init-declarations: 0 122 | no-catch-shadow: 0 123 | no-delete-var: 2 124 | no-label-var: 2 125 | no-shadow-restricted-names: 2 126 | no-shadow: 2 127 | no-undef-init: 2 128 | no-undef: 2 129 | no-undefined: 2 130 | no-unused-vars: 131 | - 2 132 | - vars: all 133 | args: none 134 | no-use-before-define: 2 135 | 136 | # Stylistic Issues 137 | 138 | array-bracket-spacing: 139 | - 2 140 | - never 141 | brace-style: 142 | - 2 143 | - stroustrup 144 | - allowSingleLine: true 145 | camelcase: 146 | - 2 147 | - properties: never 148 | comma-spacing: 149 | - 2 150 | - before: false 151 | after: true 152 | comma-style: 153 | - 2 154 | - last 155 | computed-property-spacing: 156 | - 2 157 | - never 158 | consistent-this: 159 | - 2 160 | - that 161 | eol-last: 0 162 | func-names: 0 163 | func-style: 0 164 | id-length: 0 165 | id-match: 0 166 | indent: 167 | - 2 168 | - 2 169 | - SwitchCase: 1 170 | VariableDeclarator: 2 171 | key-spacing: 172 | - 2 173 | - beforeColon: false 174 | afterColon: true 175 | lines-around-comment: 176 | - 2 177 | - beforeBlockComment: true 178 | linebreak-style: 179 | - 2 180 | - unix 181 | max-len: 182 | - 1 183 | - 120 184 | - 4 185 | max-nested-callbacks: 0 186 | new-cap: 187 | - 2 188 | - newIsCap: true 189 | capIsNew: true 190 | new-parens: 0 191 | newline-after-var: 0 192 | no-array-constructor: 2 193 | no-continue: 0 194 | no-inline-comments: 0 195 | no-lonely-if: 2 196 | no-mixed-spaces-and-tabs: 2 197 | no-multiple-empty-lines: 198 | - 2 199 | - max: 2 200 | no-nested-ternary: 0 201 | no-new-object: 2 202 | no-spaced-func: 2 203 | no-ternary: 0 204 | no-trailing-spaces: 2 205 | no-underscore-dangle: 0 206 | no-unneeded-ternary: 2 207 | object-curly-spacing: 208 | - 2 209 | - never 210 | one-var: 211 | - 2 212 | - uninitialized: always 213 | initialized: never 214 | operator-assignment: 215 | - 2 216 | - always 217 | operator-linebreak: 218 | - 2 219 | - after 220 | padded-blocks: 0 221 | quote-props: 222 | - 2 223 | - as-needed 224 | - {keywords: false} 225 | quotes: 226 | - 2 227 | - single 228 | - avoid-escape 229 | semi-spacing: 230 | - 2 231 | - before: false 232 | after: true 233 | semi: 234 | - 2 235 | - always 236 | sort-vars: 0 237 | space-after-keywords: 238 | - 2 239 | - always 240 | space-before-blocks: 241 | - 2 242 | - always 243 | space-before-function-paren: 244 | - 2 245 | - never 246 | space-in-parens: 247 | - 2 248 | - never 249 | space-infix-ops: 250 | - 2 251 | - int32Hint: false 252 | space-return-throw-case: 2 253 | space-unary-ops: 254 | - 2 255 | - words: true 256 | nonwords: false 257 | spaced-comment: 258 | - 2 259 | - always 260 | wrap-regex: 0 261 | --------------------------------------------------------------------------------