stylelint.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* vim:fileencoding=utf-8
  2. *
  3. * Copyright (C) 2023 Kovid Goyal <kovid at kovidgoyal.net>
  4. *
  5. * Distributed under terms of the GPLv3 license
  6. */
  7. /*jshint esversion: 6 */
  8. (function() {
  9. "use strict";
  10. window.stylelint_results = [];
  11. window.check_css = function(src, fix) {
  12. stylelint.lint({
  13. code: src,
  14. fix: fix,
  15. config: {
  16. rules: {
  17. 'annotation-no-unknown': true,
  18. 'at-rule-no-unknown': true,
  19. 'block-no-empty': true,
  20. 'color-no-invalid-hex': true,
  21. 'comment-no-empty': true,
  22. 'custom-property-no-missing-var-function': true,
  23. 'declaration-block-no-duplicate-custom-properties': true,
  24. 'declaration-block-no-duplicate-properties': [
  25. true,
  26. {
  27. ignore: ['consecutive-duplicates-with-different-values'],
  28. },
  29. ],
  30. 'declaration-block-no-shorthand-property-overrides': true,
  31. 'font-family-no-duplicate-names': true,
  32. 'font-family-no-missing-generic-family-keyword': true,
  33. 'function-calc-no-unspaced-operator': true,
  34. 'function-linear-gradient-no-nonstandard-direction': true,
  35. 'function-no-unknown': true,
  36. 'keyframe-block-no-duplicate-selectors': true,
  37. 'keyframe-declaration-no-important': true,
  38. 'media-feature-name-no-unknown': true,
  39. 'named-grid-areas-no-invalid': true,
  40. 'no-descending-specificity': true,
  41. 'no-duplicate-at-import-rules': true,
  42. 'no-duplicate-selectors': true,
  43. 'no-empty-source': true,
  44. 'no-extra-semicolons': true,
  45. 'no-invalid-double-slash-comments': true,
  46. 'no-invalid-position-at-import-rule': true,
  47. 'no-irregular-whitespace': true,
  48. 'property-no-unknown': true,
  49. 'selector-pseudo-class-no-unknown': true,
  50. 'selector-pseudo-element-no-unknown': true,
  51. 'selector-type-no-unknown': [
  52. true,
  53. {
  54. ignore: ['custom-elements'],
  55. },
  56. ],
  57. 'string-no-newline': true,
  58. 'unit-no-unknown': true,
  59. },
  60. },
  61. formatter: (results, returnValue) => {
  62. var r = results[0];
  63. r._postcssResult = undefined;
  64. r.source = undefined;
  65. return JSON.stringify({results:r, rule_metadata: returnValue.ruleMetadata});
  66. },
  67. })
  68. .then((results) => {
  69. window.stylelint_results.push({type: 'results', 'results':results});
  70. document.title = 'checked:' + window.performance.now();
  71. })
  72. .catch((err) => {
  73. window.stylelint_results.push({type: 'error', 'error':'' + err});
  74. console.error(err.stack);
  75. document.title = 'checked:' + window.performance.now();
  76. }) ;
  77. };
  78. window.get_css_results = function(src) {
  79. var ans = window.stylelint_results;
  80. window.stylelint_results = [];
  81. return ans;
  82. };
  83. document.title = 'ready:' + window.performance.now();
  84. })();