Skip to content

Commit

Permalink
Create check-telco-specific-terms.js
Browse files Browse the repository at this point in the history
  • Loading branch information
VijayKesharwani authored Oct 19, 2023
1 parent d316735 commit f4d8f95
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lint_function/check-telco-specific-terms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { createSuggestion } = require("@stoplight/spectral-functions");

module.exports = {
suggestInclusiveTerms: (target, inclusiveTerms, replacements) => {
const messages = [];

replacements.forEach((replacement) => {
const original = replacement.original;
const recommended = replacement.recommended;

const regex = new RegExp(replaceAll(original, /[.*+?^${}()|[\]\\]/g, "\\$&"), "g");

target.replace(regex, (match, offset) => {
messages.push(
createSuggestion(`Consider replacing '${original}' with '${recommended}'.`, {
range: {
start: offset,
end: offset + original.length,
},
})
);
});
});

return messages;
},
};

function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}

0 comments on commit f4d8f95

Please sign in to comment.