zammad-copyright.js 2.9 KB

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