knip-preprocessor.ts
1 import type { Preprocessor } from 'knip'; 2 3 const preprocess: Preprocessor = (options) => { 4 Object.keys(options.issues.exports).forEach((file) => { 5 // Ignore unused exports from files starting with "oss_" because they are used in 6 // the OSS version. This may overmatch some files that are actually unused in the 7 // OSS version but it's hard to check the OSS version in our current setup so it's 8 // fine to be conservative. 9 if (file.includes('oss_')) { 10 // Reduce `exports` counter since the exit code is based on it. 11 options.counters.exports -= Object.keys(options.issues.exports[file]).length; 12 delete options.issues.exports[file]; 13 return; 14 } 15 Object.keys(options.issues.exports[file]).forEach((exportIdentifier) => { 16 // Ignore unused exports including "oss_" because they are used in the OSS 17 // version. See above comment for explanation on why we are being conservative. 18 if (exportIdentifier.includes('oss_')) { 19 // Reduce `exports` counter since the exit code is based on it. 20 options.counters.exports -= 1; 21 delete options.issues.exports[file][exportIdentifier]; 22 } 23 }); 24 }); 25 return options; 26 }; 27 28 export default preprocess;