Skip to content

Commit

Permalink
fix: do not trim space for ignore patterns and source tags
Browse files Browse the repository at this point in the history
BREAKING CHANGE: source tags with space before opening tag will be ignored
  • Loading branch information
foray1010 committed Apr 26, 2018
1 parent cb6d548 commit a631e78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/cleanupIgnoreSyncFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const R = require('ramda')

const {COMMENT_CHAR, LINE_BREAK} = require('./constants')

const removeComment = R.compose(R.nth(0), R.split(COMMENT_CHAR))
const removeEmptyLines = R.reject((line) => line === '')
const removeTrailingSpacesAndComment = R.replace(RegExp(`\\s*(${COMMENT_CHAR}.*)?$`), '')

module.exports = R.compose(
R.join(LINE_BREAK),
removeEmptyLines,
R.map(R.compose(R.trim, removeComment)),
R.map(removeTrailingSpacesAndComment),
R.split(LINE_BREAK)
)
15 changes: 9 additions & 6 deletions src/cleanupIgnoreSyncFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ const cleanupIgnoreSyncFile = require('./cleanupIgnoreSyncFile')

describe('cleanupIgnoreSyncFile', () => {
test('should remove comments', () => {
expect(cleanupIgnoreSyncFile('pattern#')).toBe('pattern')
expect(cleanupIgnoreSyncFile('pattern#comment')).toBe('pattern')
expect(cleanupIgnoreSyncFile('pattern # comment')).toBe('pattern')
expect(cleanupIgnoreSyncFile('pat#tern # comment')).toBe('pat')
})

test('should remove empty lines', () => {
expect(cleanupIgnoreSyncFile('\n\n\npat\n\n\ntern\n\n\n')).toBe('pat\ntern')
test('should remove trailing spaces', () => {
expect(cleanupIgnoreSyncFile('pattern ')).toBe('pattern')
expect(cleanupIgnoreSyncFile('pattern ')).toBe('pattern')
expect(cleanupIgnoreSyncFile('pattern #')).toBe('pattern')
})

test('should trim spaces', () => {
expect(cleanupIgnoreSyncFile(' p a t t e r n ')).toBe(
'p a t t e r n'
)
test('should remove empty lines', () => {
expect(cleanupIgnoreSyncFile('\n\n\npat\n\n\ntern\n\n\n')).toBe('pat\ntern')
})
})
8 changes: 2 additions & 6 deletions src/decodeIgnoreSyncFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,18 @@ describe('decodeIgnoreSyncFile', () => {
const error = new Error('source `[]` not found before ignore pattern is found')
expect(() => decodeIgnoreSyncFile('pattern')).toThrow(error)
expect(() => decodeIgnoreSyncFile('pattern\n[inline]\npattern')).toThrow(error)
expect(() => decodeIgnoreSyncFile(' [inline]\npattern')).toThrow(error)

// allow empty source
expect(() => decodeIgnoreSyncFile('[]\npattern')).not.toThrow(error)
expect(() => decodeIgnoreSyncFile('[inline]\npattern\n[]\npattern')).not.toThrow(error)
expect(() => decodeIgnoreSyncFile('[]\npattern\n[inline]\npattern')).not.toThrow(error)
expect(() => decodeIgnoreSyncFile('[inline] \npattern')).not.toThrow(error)
})

test('should ignore comments', () => {
expect(
decodeIgnoreSyncFile('[inline] # comment\n# comment2\npattern\npattern2 # comment 3')
).toEqual([{source: 'inline', data: ['pattern', 'pattern2']}])
})

test('should ignore spaces', () => {
expect(decodeIgnoreSyncFile(' [ inline ] \n pattern \n pattern2 \n\n')).toEqual(
[{source: ' inline ', data: ['pattern', 'pattern2']}]
)
})
})

0 comments on commit a631e78

Please sign in to comment.