Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function reportInsert(context, offset, text) {
const pos = context.getSourceCode().getLocFromIndex(offset);
const range = [offset, offset];
context.report({
message: 'Insert `{{ code }}`',
data: { code: showInvisibles(text) },
loc: { start: pos, end: pos },
fix(fixer) {
return fixer.insertTextAfterRange(range, text);
}
});
}
differences.forEach(difference => {
let message = "";
let { line, column } = getLocFromIndex(
difference.offset,
this.source
);
switch (difference.operation) {
case INSERT:
message = `Insert \`${showInvisibles(
difference.insertText
)}\``;
break;
case DELETE:
message = `Delete \`${showInvisibles(
difference.deleteText
)}\``;
break;
case REPLACE:
message = `Replace \`${showInvisibles(
difference.deleteText
)}\` with \`${difference.insertText}\``;
break;
}
this.log({ message, line, column, source });
});
}
function reportDelete(context, offset, text) {
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context.getSourceCode().getLocFromIndex(offset + text.length);
const range = [offset, offset + text.length];
context.report({
message: 'Delete `{{ code }}`',
data: { code: showInvisibles(text) },
loc: { start, end },
fix(fixer) {
return fixer.removeRange(range);
}
});
}
insert: (code) => `Insert "${showInvisibles(code)}"`,
delete: (code) => `Delete "${showInvisibles(code)}"`,
function reportReplace(context, offset, deleteText, insertText) {
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context
.getSourceCode()
.getLocFromIndex(offset + deleteText.length);
const range = [offset, offset + deleteText.length];
context.report({
message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
data: {
deleteCode: showInvisibles(deleteText),
insertCode: showInvisibles(insertText)
},
loc: { start, end },
fix(fixer) {
return fixer.replaceTextRange(range, insertText);
}
});
}
function reportDelete(context, offset, text) {
const start = context.getSourceCode().getLocFromIndex(offset)
const end = context.getSourceCode().getLocFromIndex(offset + text.length)
const range = [offset, offset + text.length]
context.report({
message: 'Delete `{{ code }}`',
data: { code: showInvisibles(text) },
loc: { start, end },
fix(fixer) {
return fixer.removeRange(range)
},
})
}
replace: (deleteCode, insertCode) =>
`Replace "${showInvisibles(deleteCode)}" with "${showInvisibles(
insertCode
)}"`,
});
function reportReplace(context, offset, deleteText, insertText) {
const start = context.getSourceCode().getLocFromIndex(offset);
const end = context
.getSourceCode()
.getLocFromIndex(offset + deleteText.length);
const range = [offset, offset + deleteText.length];
context.report({
message: 'Replace `{{ deleteCode }}` with `{{ insertCode }}`',
data: {
deleteCode: showInvisibles(deleteText),
insertCode: showInvisibles(insertText)
},
loc: { start, end },
fix(fixer) {
return fixer.replaceTextRange(range, insertText);
}
});
}
function reportInsert(context, offset, text) {
const pos = context.getSourceCode().getLocFromIndex(offset)
const range = [offset, offset]
context.report({
message: 'Insert `{{ code }}`',
data: { code: showInvisibles(text) },
loc: { start: pos, end: pos },
fix(fixer) {
return fixer.insertTextAfterRange(range, text)
},
})
}