Skip to content

Commit

Permalink
feat: added concatenation support
Browse files Browse the repository at this point in the history
  • Loading branch information
Berkmann18 committed May 19, 2019
1 parent 191a6b0 commit 730d813
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const fixJson = (err, data, verbose) => {
} else if (comment(err)) {
fixedData = fixer.fixComment({start, fixedData, verbose})
} else if (ops(err)) {
fixedData = fixer.fixOp({start, fixedData, verbose})
fixedData = fixer.fixOpConcat({start, fixedData, verbose})
} else
throw new Error(
`Unsupported issue: ${err.message} (please open an issue at the repo)`,
Expand Down
22 changes: 11 additions & 11 deletions src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ describe('fix operations', () => {
})
})

// it('fixes concatenations', () => {
// const json = fs.readFileSync('./test/samples/concat.json', 'utf-8')
// const {data, changed} = jf(json)
// expect(changed).toBeTruthy()
// expect(data).toEqual({
// name: 'sample #25',
// type: 'JSON',
// error: 'concat',
// version: 25,
// })
// })
it('fixes concatenations', () => {
const json = fs.readFileSync('./test/samples/concat.json', 'utf-8')
const {data, changed} = jf(json)
expect(changed).toBeTruthy()
expect(data).toEqual({
name: 'sample #25',
type: 'JSON',
error: 'concat',
version: 25,
})
})

describe('multi rounds', () => {
it('x2', () => {
Expand Down
7 changes: 4 additions & 3 deletions src/fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ const fixComment = ({start, fixedData, verbose}) => {
return fixedData
}

const fixOp = ({start, fixedData, verbose}) => {
if (verbose) psw(chalk.magenta('Operations'))
const fixOpConcat = ({start, fixedData, verbose}) => {
if (verbose) psw(chalk.magenta('Operations/Concatenations'))
psw(
chalk.yellow(
'Please note: calculations made here may not be entirely correct on complex operations',
Expand All @@ -159,6 +159,7 @@ const fixOp = ({start, fixedData, verbose}) => {
eq => eval(eq),
)
.replace(/[~!+-]\(?(\d+)\)?/g, eq => eval(eq))
.replace(/(":\s*)"(.*?)"\s*\+\s*"(.*?)"/g, '$1"$2$3"')
/* eslint-enable no-eval */
fixedData[targetLine] = fixedLine
return fixedData
Expand All @@ -172,5 +173,5 @@ module.exports = {
fixSquareBrackets,
fixCurlyBrackets,
fixComment,
fixOp,
fixOpConcat,
}
2 changes: 1 addition & 1 deletion test/samples/concat.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "sample" + "#25",
"name": "sample " + "#25",
"type": "JSON",
"error": "concat",
"version": 25
Expand Down

0 comments on commit 730d813

Please sign in to comment.