From fbbadad1c80ba30571b22c282812db12728d0102 Mon Sep 17 00:00:00 2001 From: Vaughan Rouesnel Date: Sun, 18 Nov 2018 13:55:06 +0100 Subject: [PATCH 1/3] Capitalize babel template substitutions --- .../__snapshots__/index.test.js.snap | 30 ++--- src/scope/templates/index.js | 38 +++--- src/scope/templates/index.test.js | 114 +++++++++--------- 3 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/scope/templates/__snapshots__/index.test.js.snap b/src/scope/templates/__snapshots__/index.test.js.snap index 4c5323a..5fd4716 100644 --- a/src/scope/templates/__snapshots__/index.test.js.snap +++ b/src/scope/templates/__snapshots__/index.test.js.snap @@ -3,9 +3,9 @@ exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 0 1`] = ` " if (typeof window !== 'undefined') { - console.groupCollapsed(title); + console.groupCollapsed(TITLE); } else { - console.log('▼ ', title); + console.log('▼ ', TITLE); } " `; @@ -13,9 +13,9 @@ exports[`Templates .buildGroupCollapsed calls template with correct string and i exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 1 1`] = ` " if (typeof window !== 'undefined') { - console.groupCollapsed(title); + console.groupCollapsed(TITLE); } else { - console.log('| ▼ ', title); + console.log('| ▼ ', TITLE); } " `; @@ -23,9 +23,9 @@ exports[`Templates .buildGroupCollapsed calls template with correct string and i exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 2 1`] = ` " if (typeof window !== 'undefined') { - console.groupCollapsed(title); + console.groupCollapsed(TITLE); } else { - console.log('| | ▼ ', title); + console.log('| | ▼ ', TITLE); } " `; @@ -33,9 +33,9 @@ exports[`Templates .buildGroupCollapsed calls template with correct string and i exports[`Templates .buildGroupCollapsed calls template with correct string and indentation level: 3 1`] = ` " if (typeof window !== 'undefined') { - console.groupCollapsed(title); + console.groupCollapsed(TITLE); } else { - console.log('| | | ▼ ', title); + console.log('| | | ▼ ', TITLE); } " `; @@ -43,7 +43,7 @@ exports[`Templates .buildGroupCollapsed calls template with correct string and i exports[`Templates .buildGroupEnd calls template with correct string 1`] = ` " if (typeof window !== 'undefined') { - console.groupEnd(title); + console.groupEnd(TITLE); } " `; @@ -51,9 +51,9 @@ exports[`Templates .buildGroupEnd calls template with correct string 1`] = ` exports[`Templates .buildLog calls template with correct string and indentation level: 1 1`] = ` " if (typeof window !== 'undefined') { - console.log(args); + console.log(ARGS); } else { - console.log('| | ', args); + console.log('| | ', ARGS); } " @@ -62,9 +62,9 @@ exports[`Templates .buildLog calls template with correct string and indentation exports[`Templates .buildLog calls template with correct string and indentation level: 2 1`] = ` " if (typeof window !== 'undefined') { - console.log(args); + console.log(ARGS); } else { - console.log('| | | ', args); + console.log('| | | ', ARGS); } " @@ -73,9 +73,9 @@ exports[`Templates .buildLog calls template with correct string and indentation exports[`Templates .buildLog calls template with correct string and indentation level: 3 1`] = ` " if (typeof window !== 'undefined') { - console.log(args); + console.log(ARGS); } else { - console.log('| | | | ', args); + console.log('| | | | ', ARGS); } " diff --git a/src/scope/templates/index.js b/src/scope/templates/index.js index f8eb8b3..7682b56 100644 --- a/src/scope/templates/index.js +++ b/src/scope/templates/index.js @@ -1,42 +1,42 @@ -const buildGroupCollapsed = template => title => level => { - const indentation = indentWith(level, '| ', '▼ '); +const buildGroupCollapsed = template => TITLE => level => { + const indentation = indentWith(level, '| ', '▼ ') return template(` if (typeof window !== 'undefined') { - console.groupCollapsed(title); + console.groupCollapsed(TITLE); } else { - console.log('${indentation}', title); + console.log('${indentation}', TITLE); } - `)({ title }); -}; + `)({TITLE}) +} -const buildGroupEnd = template => title => +const buildGroupEnd = template => TITLE => template(` if (typeof window !== 'undefined') { - console.groupEnd(title); + console.groupEnd(TITLE); } -`)({ title }); +`)({TITLE}) -const buildLog = template => (...args) => level => { +const buildLog = template => (...ARGS) => level => { if (level == 0) { - return template('console.log(args);')({ args }); + return template('console.log(ARGS);')({ARGS}) } - const indentation = indentWith(level, '| ', '| '); + const indentation = indentWith(level, '| ', '| ') return template(` if (typeof window !== 'undefined') { - console.log(args); + console.log(ARGS); } else { - console.log('${indentation}', args); + console.log('${indentation}', ARGS); } - `)({ args }); -}; + `)({ARGS}) +} -const indentWith = (level, str, initial) => Array.from({ length: level }).reduce(acc => `${str}${acc}`, initial); +const indentWith = (level, str, initial) => Array.from({length: level}).reduce(acc => `${str}${acc}`, initial) export default template => ({ buildGroupCollapsed: buildGroupCollapsed(template), buildGroupEnd: buildGroupEnd(template), - buildLog: buildLog(template) -}); + buildLog: buildLog(template), +}) diff --git a/src/scope/templates/index.test.js b/src/scope/templates/index.test.js index 42cf759..5a420a9 100644 --- a/src/scope/templates/index.test.js +++ b/src/scope/templates/index.test.js @@ -1,83 +1,83 @@ -import each from 'jest-each'; +import each from 'jest-each' -import templateHelpers from './'; +import templateHelpers from './' describe('Templates', () => { - const noop = () => {}; + const noop = () => {} describe('.buildGroupCollapsed', () => { each([[0], [1], [2], [3]]).it('calls template with correct string and indentation level: %d', level => { - const template = jest.fn(() => noop); - const { buildGroupCollapsed } = templateHelpers(template); - buildGroupCollapsed('bob')(level); - expect(template.mock.calls[0][0]).toMatchSnapshot(); - }); + const template = jest.fn(() => noop) + const {buildGroupCollapsed} = templateHelpers(template) + buildGroupCollapsed('bob')(level) + expect(template.mock.calls[0][0]).toMatchSnapshot() + }) it('invokes template with given title as an object', () => { - const template = () => templateCurry; - const templateCurry = jest.fn(); - const { buildGroupCollapsed } = templateHelpers(template); - buildGroupCollapsed('matt')(0); - expect(templateCurry).toHaveBeenCalledWith({ title: 'matt' }); - }); + const template = () => templateCurry + const templateCurry = jest.fn() + const {buildGroupCollapsed} = templateHelpers(template) + buildGroupCollapsed('matt')(0) + expect(templateCurry).toHaveBeenCalledWith({TITLE: 'matt'}) + }) it('returns value from invoking template', () => { - const template = () => () => 'hello world'; - const { buildGroupCollapsed } = templateHelpers(template); - expect(buildGroupCollapsed('matt', 'woz', 'ere')(0)).toBe('hello world'); - }); - }); + const template = () => () => 'hello world' + const {buildGroupCollapsed} = templateHelpers(template) + expect(buildGroupCollapsed('matt', 'woz', 'ere')(0)).toBe('hello world') + }) + }) describe('.buildGroupEnd', () => { it('calls template with correct string', () => { - const template = jest.fn(() => noop); - const { buildGroupEnd } = templateHelpers(template); - buildGroupEnd('bob'); - expect(template.mock.calls[0][0]).toMatchSnapshot(); - }); + const template = jest.fn(() => noop) + const {buildGroupEnd} = templateHelpers(template) + buildGroupEnd('bob') + expect(template.mock.calls[0][0]).toMatchSnapshot() + }) it('invokes template with given title as an object', () => { - const template = () => templateCurry; - const templateCurry = jest.fn(); - const { buildGroupEnd } = templateHelpers(template); - buildGroupEnd('matt'); - expect(templateCurry).toHaveBeenCalledWith({ title: 'matt' }); - }); + const template = () => templateCurry + const templateCurry = jest.fn() + const {buildGroupEnd} = templateHelpers(template) + buildGroupEnd('matt') + expect(templateCurry).toHaveBeenCalledWith({TITLE: 'matt'}) + }) it('returns value from invoking template', () => { - const template = () => () => 'hello world'; - const { buildGroupEnd } = templateHelpers(template); - expect(buildGroupEnd('matt', 'woz', 'ere')).toBe('hello world'); - }); - }); + const template = () => () => 'hello world' + const {buildGroupEnd} = templateHelpers(template) + expect(buildGroupEnd('matt', 'woz', 'ere')).toBe('hello world') + }) + }) describe('.buildLog', () => { it('calls template with console log string when indentation level is 0', () => { - const template = jest.fn(() => noop); - const { buildLog } = templateHelpers(template); - buildLog('bob', 'woz', 'ere')(0); - expect(template).toHaveBeenCalledWith('console.log(args);'); - }); + const template = jest.fn(() => noop) + const {buildLog} = templateHelpers(template) + buildLog('bob', 'woz', 'ere')(0) + expect(template).toHaveBeenCalledWith('console.log(ARGS);') + }) each([[1], [2], [3]]).it('calls template with correct string and indentation level: %d', level => { - const template = jest.fn(() => noop); - const { buildLog } = templateHelpers(template); - buildLog('bob', 'woz', 'ere')(level); - expect(template.mock.calls[0][0]).toMatchSnapshot(); - }); + const template = jest.fn(() => noop) + const {buildLog} = templateHelpers(template) + buildLog('bob', 'woz', 'ere')(level) + expect(template.mock.calls[0][0]).toMatchSnapshot() + }) it('invokes template with given args as an object', () => { - const template = () => templateCurry; - const templateCurry = jest.fn(); - const { buildLog } = templateHelpers(template); - buildLog('matt', 'woz', 'ere')(0); - expect(templateCurry).toHaveBeenCalledWith({ args: ['matt', 'woz', 'ere'] }); - }); + const template = () => templateCurry + const templateCurry = jest.fn() + const {buildLog} = templateHelpers(template) + buildLog('matt', 'woz', 'ere')(0) + expect(templateCurry).toHaveBeenCalledWith({ARGS: ['matt', 'woz', 'ere']}) + }) it('returns value from invoking template', () => { - const template = () => () => 'hello world'; - const { buildLog } = templateHelpers(template); - expect(buildLog('matt', 'woz', 'ere')(0)).toBe('hello world'); - }); - }); -}); + const template = () => () => 'hello world' + const {buildLog} = templateHelpers(template) + expect(buildLog('matt', 'woz', 'ere')(0)).toBe('hello world') + }) + }) +}) From c422375f68e23858686dc3752b6a4cf5abe6ece7 Mon Sep 17 00:00:00 2001 From: Vaughan Rouesnel Date: Sun, 18 Nov 2018 14:16:02 +0100 Subject: [PATCH 2/3] Add --no-config to npm run prettier to prevent user's global config being used --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 853df7a..cd8152a 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "lint:fix": "yarn lint -- --fix", "precommit": "lint-staged", "prepublish": "yarn build", - "prettier": "prettier 'src/**/*.js' --write --single-quote=true --print-width=120", + "prettier": "prettier 'src/**/*.js' --write --single-quote=true --print-width=120 --no-config", "test": "jest", "test:coverage": "yarn test -- --coverage", "test:report": "codecov", From 97c304a89a2b5f0e3ddc4288d63ee88cd993b220 Mon Sep 17 00:00:00 2001 From: Vaughan Rouesnel Date: Sun, 18 Nov 2018 14:16:53 +0100 Subject: [PATCH 3/3] Fix lint issues --- src/scope/templates/index.js | 22 +++--- src/scope/templates/index.test.js | 114 +++++++++++++++--------------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/scope/templates/index.js b/src/scope/templates/index.js index 7682b56..1445196 100644 --- a/src/scope/templates/index.js +++ b/src/scope/templates/index.js @@ -1,5 +1,5 @@ const buildGroupCollapsed = template => TITLE => level => { - const indentation = indentWith(level, '| ', '▼ ') + const indentation = indentWith(level, '| ', '▼ '); return template(` if (typeof window !== 'undefined') { @@ -7,22 +7,22 @@ const buildGroupCollapsed = template => TITLE => level => { } else { console.log('${indentation}', TITLE); } - `)({TITLE}) -} + `)({ TITLE }); +}; const buildGroupEnd = template => TITLE => template(` if (typeof window !== 'undefined') { console.groupEnd(TITLE); } -`)({TITLE}) +`)({ TITLE }); const buildLog = template => (...ARGS) => level => { if (level == 0) { - return template('console.log(ARGS);')({ARGS}) + return template('console.log(ARGS);')({ ARGS }); } - const indentation = indentWith(level, '| ', '| ') + const indentation = indentWith(level, '| ', '| '); return template(` if (typeof window !== 'undefined') { console.log(ARGS); @@ -30,13 +30,13 @@ const buildLog = template => (...ARGS) => level => { console.log('${indentation}', ARGS); } - `)({ARGS}) -} + `)({ ARGS }); +}; -const indentWith = (level, str, initial) => Array.from({length: level}).reduce(acc => `${str}${acc}`, initial) +const indentWith = (level, str, initial) => Array.from({ length: level }).reduce(acc => `${str}${acc}`, initial); export default template => ({ buildGroupCollapsed: buildGroupCollapsed(template), buildGroupEnd: buildGroupEnd(template), - buildLog: buildLog(template), -}) + buildLog: buildLog(template) +}); diff --git a/src/scope/templates/index.test.js b/src/scope/templates/index.test.js index 5a420a9..ff8e3b0 100644 --- a/src/scope/templates/index.test.js +++ b/src/scope/templates/index.test.js @@ -1,83 +1,83 @@ -import each from 'jest-each' +import each from 'jest-each'; -import templateHelpers from './' +import templateHelpers from './'; describe('Templates', () => { - const noop = () => {} + const noop = () => {}; describe('.buildGroupCollapsed', () => { each([[0], [1], [2], [3]]).it('calls template with correct string and indentation level: %d', level => { - const template = jest.fn(() => noop) - const {buildGroupCollapsed} = templateHelpers(template) - buildGroupCollapsed('bob')(level) - expect(template.mock.calls[0][0]).toMatchSnapshot() - }) + const template = jest.fn(() => noop); + const { buildGroupCollapsed } = templateHelpers(template); + buildGroupCollapsed('bob')(level); + expect(template.mock.calls[0][0]).toMatchSnapshot(); + }); it('invokes template with given title as an object', () => { - const template = () => templateCurry - const templateCurry = jest.fn() - const {buildGroupCollapsed} = templateHelpers(template) - buildGroupCollapsed('matt')(0) - expect(templateCurry).toHaveBeenCalledWith({TITLE: 'matt'}) - }) + const template = () => templateCurry; + const templateCurry = jest.fn(); + const { buildGroupCollapsed } = templateHelpers(template); + buildGroupCollapsed('matt')(0); + expect(templateCurry).toHaveBeenCalledWith({ TITLE: 'matt' }); + }); it('returns value from invoking template', () => { - const template = () => () => 'hello world' - const {buildGroupCollapsed} = templateHelpers(template) - expect(buildGroupCollapsed('matt', 'woz', 'ere')(0)).toBe('hello world') - }) - }) + const template = () => () => 'hello world'; + const { buildGroupCollapsed } = templateHelpers(template); + expect(buildGroupCollapsed('matt', 'woz', 'ere')(0)).toBe('hello world'); + }); + }); describe('.buildGroupEnd', () => { it('calls template with correct string', () => { - const template = jest.fn(() => noop) - const {buildGroupEnd} = templateHelpers(template) - buildGroupEnd('bob') - expect(template.mock.calls[0][0]).toMatchSnapshot() - }) + const template = jest.fn(() => noop); + const { buildGroupEnd } = templateHelpers(template); + buildGroupEnd('bob'); + expect(template.mock.calls[0][0]).toMatchSnapshot(); + }); it('invokes template with given title as an object', () => { - const template = () => templateCurry - const templateCurry = jest.fn() - const {buildGroupEnd} = templateHelpers(template) - buildGroupEnd('matt') - expect(templateCurry).toHaveBeenCalledWith({TITLE: 'matt'}) - }) + const template = () => templateCurry; + const templateCurry = jest.fn(); + const { buildGroupEnd } = templateHelpers(template); + buildGroupEnd('matt'); + expect(templateCurry).toHaveBeenCalledWith({ TITLE: 'matt' }); + }); it('returns value from invoking template', () => { - const template = () => () => 'hello world' - const {buildGroupEnd} = templateHelpers(template) - expect(buildGroupEnd('matt', 'woz', 'ere')).toBe('hello world') - }) - }) + const template = () => () => 'hello world'; + const { buildGroupEnd } = templateHelpers(template); + expect(buildGroupEnd('matt', 'woz', 'ere')).toBe('hello world'); + }); + }); describe('.buildLog', () => { it('calls template with console log string when indentation level is 0', () => { - const template = jest.fn(() => noop) - const {buildLog} = templateHelpers(template) - buildLog('bob', 'woz', 'ere')(0) - expect(template).toHaveBeenCalledWith('console.log(ARGS);') - }) + const template = jest.fn(() => noop); + const { buildLog } = templateHelpers(template); + buildLog('bob', 'woz', 'ere')(0); + expect(template).toHaveBeenCalledWith('console.log(ARGS);'); + }); each([[1], [2], [3]]).it('calls template with correct string and indentation level: %d', level => { - const template = jest.fn(() => noop) - const {buildLog} = templateHelpers(template) - buildLog('bob', 'woz', 'ere')(level) - expect(template.mock.calls[0][0]).toMatchSnapshot() - }) + const template = jest.fn(() => noop); + const { buildLog } = templateHelpers(template); + buildLog('bob', 'woz', 'ere')(level); + expect(template.mock.calls[0][0]).toMatchSnapshot(); + }); it('invokes template with given args as an object', () => { - const template = () => templateCurry - const templateCurry = jest.fn() - const {buildLog} = templateHelpers(template) - buildLog('matt', 'woz', 'ere')(0) - expect(templateCurry).toHaveBeenCalledWith({ARGS: ['matt', 'woz', 'ere']}) - }) + const template = () => templateCurry; + const templateCurry = jest.fn(); + const { buildLog } = templateHelpers(template); + buildLog('matt', 'woz', 'ere')(0); + expect(templateCurry).toHaveBeenCalledWith({ ARGS: ['matt', 'woz', 'ere'] }); + }); it('returns value from invoking template', () => { - const template = () => () => 'hello world' - const {buildLog} = templateHelpers(template) - expect(buildLog('matt', 'woz', 'ere')(0)).toBe('hello world') - }) - }) -}) + const template = () => () => 'hello world'; + const { buildLog } = templateHelpers(template); + expect(buildLog('matt', 'woz', 'ere')(0)).toBe('hello world'); + }); + }); +});