@exbotanical/eslint-config 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11635,6 +11635,18 @@ interface OptionsJsonc extends AllOptions, OptionsSortKeys {
11635
11635
  indent?: 'tab' | number;
11636
11636
  }
11637
11637
 
11638
+ interface OptionsMarkdown extends AllOptions {
11639
+ /**
11640
+ * Lints the code blocks inside Markdown files as source files. Code blocks are often
11641
+ * documentation examples, including intentional counterexamples, so autofix rules that
11642
+ * reorder or remove code are turned off for them. Other fixes still rewrite them.
11643
+ * `overrides` passed here apply to the code blocks.
11644
+ *
11645
+ * @default false
11646
+ */
11647
+ lintCodeBlocks?: boolean | OptionsOverrides;
11648
+ }
11649
+
11638
11650
  interface OptionsPerfectionist extends AllOptions {
11639
11651
  /**
11640
11652
  * Sorts declarations whose order can carry meaning: interfaces, object types, enums,
@@ -11790,11 +11802,12 @@ interface OptionsConfig extends OptionsProjectType {
11790
11802
  */
11791
11803
  toml?: boolean | OptionsToml;
11792
11804
  /**
11793
- * Enables linting for Markdown and Markdown code snippets.
11794
- * TODO: update rules
11805
+ * Enables Markdown document rules. Code blocks are linted only when
11806
+ * `lintCodeBlocks` is set.
11807
+ *
11795
11808
  * @default true
11796
11809
  */
11797
- markdown?: boolean | (OptionsOverrides & OptionsFiles);
11810
+ markdown?: boolean | OptionsMarkdown;
11798
11811
  /**
11799
11812
  * Configurable global ignores.
11800
11813
  */
package/dist/index.js CHANGED
@@ -903,33 +903,53 @@ var JsxConfig = class extends CustomConfig {
903
903
  // src/configs/markdown.ts
904
904
  var MarkdownConfig = class extends CustomConfig {
905
905
  namespace = "markdown";
906
- constructor({ files = [GLOB_MARKDOWN], ...rest } = {}) {
906
+ constructor({
907
+ files = [GLOB_MARKDOWN],
908
+ lintCodeBlocks = false,
909
+ ...rest
910
+ } = {}) {
907
911
  super({
908
912
  files,
913
+ lintCodeBlocks,
909
914
  ...rest
910
915
  });
911
916
  }
912
917
  async _rules() {
913
- const { files = [GLOB_MARKDOWN], overrides = {} } = this.options;
918
+ const {
919
+ files = [GLOB_MARKDOWN],
920
+ lintCodeBlocks = false,
921
+ overrides = {}
922
+ } = this.options;
914
923
  const markdown = await interopDefault(import("@eslint/markdown"));
915
924
  return [
916
925
  this.createRuleConfig("setup", {
917
926
  plugins: { markdown }
918
927
  }),
919
- this.createRuleConfig("processor", {
920
- files,
921
- ignores: ["**/*.md/*.md"],
922
- // `eslint-plugin-markdown` only creates virtual files for code blocks,
923
- // but not the markdown file itself (we use passthrough for this).
924
- processor: mergeProcessors([markdown.processors.markdown, processorPassThrough])
925
- }),
926
928
  this.createRuleConfig("rules", {
927
929
  files,
928
930
  language: "markdown/gfm",
929
931
  rules: {
930
- ...markdown.configs.recommended[0].rules
932
+ ...markdown.configs.recommended[0].rules,
933
+ ...overrides
931
934
  }
932
935
  }),
936
+ ...lintCodeBlocks ? this.codeBlockRules(files, markdown, lintCodeBlocks) : []
937
+ ];
938
+ }
939
+ /**
940
+ * Builds the records that extract code blocks into virtual files and turn off the
941
+ * rules that do not fit documentation examples.
942
+ */
943
+ codeBlockRules(files, markdown, lintCodeBlocks) {
944
+ const codeBlockOverrides = lintCodeBlocks === true ? {} : lintCodeBlocks.overrides ?? {};
945
+ return [
946
+ this.createRuleConfig("processor", {
947
+ files,
948
+ ignores: ["**/*.md/*.md"],
949
+ // The markdown processor only creates virtual files for code blocks, but not
950
+ // the markdown file itself (we use passthrough for this).
951
+ processor: mergeProcessors([markdown.processors.markdown, processorPassThrough])
952
+ }),
933
953
  this.createRuleConfig("disables", {
934
954
  files: [GLOB_MARKDOWN_CODE],
935
955
  languageOptions: {
@@ -938,7 +958,13 @@ var MarkdownConfig = class extends CustomConfig {
938
958
  }
939
959
  },
940
960
  rules: {
961
+ "import/first": "off",
941
962
  "import/newline-after-import": "off",
963
+ "import/no-duplicates": "off",
964
+ "import/no-empty-named-blocks": "off",
965
+ "import/order": "off",
966
+ "jsdoc/no-blank-blocks": "off",
967
+ "jsdoc/sort-tags": "off",
942
968
  "no-alert": "off",
943
969
  "no-console": "off",
944
970
  "no-labels": "off",
@@ -948,7 +974,24 @@ var MarkdownConfig = class extends CustomConfig {
948
974
  "no-unused-expressions": "off",
949
975
  "no-unused-labels": "off",
950
976
  "no-unused-vars": "off",
977
+ "no-useless-return": "off",
951
978
  "node/prefer-global/process": "off",
979
+ "perfectionist/sort-array-includes": "off",
980
+ "perfectionist/sort-classes": "off",
981
+ "perfectionist/sort-enums": "off",
982
+ "perfectionist/sort-exports": "off",
983
+ "perfectionist/sort-heritage-clauses": "off",
984
+ "perfectionist/sort-interfaces": "off",
985
+ "perfectionist/sort-intersection-types": "off",
986
+ "perfectionist/sort-modules": "off",
987
+ "perfectionist/sort-named-exports": "off",
988
+ "perfectionist/sort-named-imports": "off",
989
+ "perfectionist/sort-object-types": "off",
990
+ "perfectionist/sort-sets": "off",
991
+ "perfectionist/sort-union-types": "off",
992
+ "regexp/sort-alternatives": "off",
993
+ "regexp/sort-character-class-elements": "off",
994
+ "regexp/sort-flags": "off",
952
995
  "style/comma-dangle": "off",
953
996
  "style/eol-last": "off",
954
997
  "ts/consistent-type-imports": "off",
@@ -960,9 +1003,10 @@ var MarkdownConfig = class extends CustomConfig {
960
1003
  "ts/no-unused-vars": "off",
961
1004
  "ts/no-use-before-define": "off",
962
1005
  "unicode-bom": "off",
1006
+ "unicorn/prefer-export-from": "off",
963
1007
  "unused-imports/no-unused-imports": "off",
964
1008
  "unused-imports/no-unused-vars": "off",
965
- ...overrides
1009
+ ...codeBlockOverrides
966
1010
  }
967
1011
  })
968
1012
  ];
@@ -1491,6 +1535,18 @@ var eslint_config_prettier_default = {
1491
1535
  };
1492
1536
 
1493
1537
  // src/configs/prettier.ts
1538
+ var FORMAT_PLUGIN_RULES = {
1539
+ "jsonc/comma-dangle": "off",
1540
+ "jsonc/indent": "off",
1541
+ "jsonc/quote-props": "off",
1542
+ "jsonc/quotes": "off",
1543
+ "toml/array-bracket-spacing": "off",
1544
+ "toml/array-element-newline": "off",
1545
+ "toml/indent": "off",
1546
+ "yaml/flow-mapping-curly-spacing": "off",
1547
+ "yaml/indent": "off",
1548
+ "yaml/quotes": "off"
1549
+ };
1494
1550
  var PrettierConfig = class extends CustomConfig {
1495
1551
  namespace = "prettier";
1496
1552
  constructor(options = {}) {
@@ -1502,6 +1558,7 @@ var PrettierConfig = class extends CustomConfig {
1502
1558
  ...eslint_config_prettier_default,
1503
1559
  rules: {
1504
1560
  ...eslint_config_prettier_default.rules,
1561
+ ...FORMAT_PLUGIN_RULES,
1505
1562
  ...this.options.overrides
1506
1563
  }
1507
1564
  })
@@ -2510,9 +2567,6 @@ async function exbotanical({
2510
2567
  if (optionsCss) {
2511
2568
  configs2.push(new CssConfig({ ...factoryConfig(optionsCss) }).rules());
2512
2569
  }
2513
- if (optionsMarkdown) {
2514
- configs2.push(new MarkdownConfig({ ...factoryConfig(optionsMarkdown) }).rules());
2515
- }
2516
2570
  if (optionsGraphql) {
2517
2571
  configs2.push(new GraphqlConfig().rules());
2518
2572
  }
@@ -2539,6 +2593,9 @@ async function exbotanical({
2539
2593
  new YamlConfig({ ...factoryConfig(optionsYaml), ...optionsStyle }).rules()
2540
2594
  );
2541
2595
  }
2596
+ if (optionsMarkdown) {
2597
+ configs2.push(new MarkdownConfig({ ...factoryConfig(optionsMarkdown) }).rules());
2598
+ }
2542
2599
  configs2.push(
2543
2600
  new DataFilesConfig({
2544
2601
  files: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exbotanical/eslint-config",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.1.0",
5
5
  "private": false,
6
6
  "description": "Zito's eslint config",
7
7
  "author": "Matthew Zito <exbotanical@protonmail.com> (https://github.com/exbotanical/)",