errors.mjs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { EXIT_CODE_INVALID_CONFIG, EXIT_CODE_INVALID_USAGE } from '../constants.mjs';
  2. export class ConfigurationError extends Error {
  3. name = 'ConfigurationError';
  4. code = EXIT_CODE_INVALID_CONFIG;
  5. /**
  6. * @param {string} message
  7. */
  8. constructor(message) {
  9. super(message);
  10. }
  11. }
  12. export class AllFilesIgnoredError extends Error {
  13. name = 'AllFilesIgnoredError';
  14. constructor() {
  15. super(
  16. 'All input files were ignored because of the ignore pattern. Either change your input, ignore pattern or use "--allow-empty-input" to allow no inputs',
  17. );
  18. }
  19. }
  20. export class NoFilesFoundError extends Error {
  21. name = 'NoFilesFoundError';
  22. /**
  23. * @param {string|string[]} fileList
  24. */
  25. constructor(fileList) {
  26. super();
  27. if (typeof fileList === 'string') {
  28. fileList = [fileList];
  29. }
  30. const pattern = fileList.filter((i) => !i.startsWith('!')).join(', ');
  31. this.message = `No files matching the pattern "${pattern}" were found.`;
  32. }
  33. }
  34. export class SuppressionFileNotFoundError extends Error {
  35. name = 'SuppressionFileNotFoundError';
  36. code = EXIT_CODE_INVALID_USAGE;
  37. constructor() {
  38. super(
  39. 'The suppressions file does not exist. Please run the command with "--suppress" or "--suppress=<rule>" to create it.',
  40. );
  41. }
  42. }