zammad-copyright.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. /**
  3. * @fileoverview Enforce presence of Zammad copyright header
  4. * @author Martin Gruner
  5. */
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const { RuleTester } = require('eslint')
  10. const rule = require('../../../lib/rules/zammad-copyright.js')
  11. //------------------------------------------------------------------------------
  12. // Tests
  13. //------------------------------------------------------------------------------
  14. // NOTE: Cannot test with xml tags inside vue files, as the preprocessors are not running.
  15. const year = new Date().getYear() + 1900
  16. const ruleTester = new RuleTester()
  17. ruleTester.run('zammad-copyright', rule, {
  18. valid: [
  19. {
  20. filename: 'test.ts',
  21. code: `// Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/`,
  22. },
  23. {
  24. filename: 'test.js',
  25. code: `// Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/`,
  26. },
  27. {
  28. filename: 'test.vue',
  29. code: `<!-- Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/ -->`,
  30. },
  31. // Empty file, no change.
  32. {
  33. filename: 'test.js',
  34. code: '',
  35. },
  36. ],
  37. invalid: [
  38. {
  39. filename: 'test.js',
  40. code: 'function foo(){}',
  41. errors: [{ message: 'Missing Zammad copyright header.' }],
  42. output: `// Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/\n\nfunction foo(){}`,
  43. },
  44. {
  45. filename: 'test.js',
  46. code: '// Copyright some other value\n\n\nfunction foo(){}',
  47. errors: [{ message: 'Wrong Zammad copyright header.' }],
  48. output: `// Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/\n\n\nfunction foo(){}`,
  49. },
  50. {
  51. filename: 'test.js',
  52. code: `// Copyright (C) 2012-${
  53. year - 1
  54. } Zammad Foundation, https://zammad-foundation.org/\n\n\nfunction foo(){}`,
  55. errors: [{ message: 'Wrong Zammad copyright header.' }],
  56. output: `// Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/\n\n\nfunction foo(){}`,
  57. },
  58. {
  59. filename: 'test.vue',
  60. code: 'function foo(){}',
  61. errors: [{ message: 'Missing Zammad copyright header.' }],
  62. output: `<!-- Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/ -->\n\nfunction foo(){}`,
  63. },
  64. {
  65. filename: 'test.vue',
  66. code: '<!-- Copyright some other value -->\n\n\n',
  67. errors: [{ message: 'Wrong Zammad copyright header.' }],
  68. output: `<!-- Copyright (C) 2012-${year} Zammad Foundation, https://zammad-foundation.org/ -->\n\n\n`,
  69. },
  70. ],
  71. })