@mrpalmer/eslint-plugin 1.0.3 → 1.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/lib/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { TSESLint } from '@typescript-eslint/utils';
2
+ type PluginRules = Record<string, TSESLint.RuleModule<string, readonly unknown[]>>;
2
3
  declare const _default: {
3
4
  configs: {
4
5
  recommended: {
@@ -9,11 +10,7 @@ declare const _default: {
9
10
  name: string;
10
11
  version: string;
11
12
  };
12
- rules: {
13
- 'shorten-paths': TSESLint.RuleModule<"shortenImport" | "shortenExport", import("./rules/shorten-paths.js").Options, unknown, TSESLint.RuleListener>;
14
- 'sort-imports': TSESLint.RuleModule<"error" | "order" | "noLineBetweenImports", [import("./rules/sort-imports.js").Options], unknown, TSESLint.RuleListener>;
15
- 'sort-named': TSESLint.RuleModule<"order", [import("./rules/sort-named.js").Options], unknown, TSESLint.RuleListener>;
16
- };
13
+ rules: PluginRules;
17
14
  };
18
15
  };
19
16
  rules: {
@@ -22,15 +19,12 @@ declare const _default: {
22
19
  'mrpalmer/sort-named': "warn";
23
20
  };
24
21
  };
22
+ json: TSESLint.FlatConfig.Config;
25
23
  };
26
24
  meta: {
27
25
  name: string;
28
26
  version: string;
29
27
  };
30
- rules: {
31
- 'shorten-paths': TSESLint.RuleModule<"shortenImport" | "shortenExport", import("./rules/shorten-paths.js").Options, unknown, TSESLint.RuleListener>;
32
- 'sort-imports': TSESLint.RuleModule<"error" | "order" | "noLineBetweenImports", [import("./rules/sort-imports.js").Options], unknown, TSESLint.RuleListener>;
33
- 'sort-named': TSESLint.RuleModule<"order", [import("./rules/sort-named.js").Options], unknown, TSESLint.RuleListener>;
34
- };
28
+ rules: PluginRules;
35
29
  };
36
30
  export default _default;
package/lib/index.js CHANGED
@@ -1,9 +1,13 @@
1
+ import jsonPlugin from '@eslint/json';
1
2
  import { meta } from './meta.js';
2
3
  // rules
4
+ import requirePackageScope from './rules/require-package-scope.js';
3
5
  import shortenPathsRule from './rules/shorten-paths.js';
4
6
  import sortImportsRule from './rules/sort-imports.js';
5
7
  import sortNamedRule from './rules/sort-named.js';
6
8
  const rules = {
9
+ // @ts-expect-error -- require-package-scope is a JSON rule
10
+ 'require-package-scope': requirePackageScope,
7
11
  'shorten-paths': shortenPathsRule,
8
12
  'sort-imports': sortImportsRule,
9
13
  'sort-named': sortNamedRule,
@@ -23,9 +27,18 @@ const recommended = {
23
27
  'mrpalmer/sort-named': 'warn',
24
28
  },
25
29
  };
30
+ const json = {
31
+ name: 'mrpalmer/json',
32
+ plugins: {
33
+ json: jsonPlugin,
34
+ mrpalmer: plugin,
35
+ },
36
+ language: 'json/json',
37
+ };
26
38
  export default {
27
39
  ...plugin,
28
40
  configs: {
29
41
  recommended,
42
+ json,
30
43
  },
31
44
  };
@@ -0,0 +1,11 @@
1
+ import type { JSONRuleDefinition } from '@eslint/json/types';
2
+ export type MessageIds = 'requirePackageScope' | 'forbidPackageScope';
3
+ export type RuleOptions = [{
4
+ scope: string | false;
5
+ }];
6
+ export type RequirePackageScopeRuleDefinition = JSONRuleDefinition<{
7
+ RuleOptions: RuleOptions;
8
+ MessageIds: MessageIds;
9
+ }>;
10
+ declare const rule: RequirePackageScopeRuleDefinition;
11
+ export default rule;
@@ -0,0 +1,54 @@
1
+ const rule = {
2
+ meta: {
3
+ type: 'suggestion',
4
+ docs: {
5
+ description: 'Require or forbid package scopes in package names.',
6
+ },
7
+ schema: [
8
+ {
9
+ type: 'object',
10
+ properties: {
11
+ scope: {
12
+ anyOf: [{ type: 'string' }, { type: 'boolean', enum: [false] }],
13
+ description: 'The required scope for package names, or false to forbid scopes.',
14
+ },
15
+ },
16
+ additionalProperties: false,
17
+ },
18
+ ],
19
+ defaultOptions: [{ scope: false }],
20
+ messages: {
21
+ requirePackageScope: 'Packages must use the "@{{scope}}" scope.',
22
+ forbidPackageScope: 'Packages must not use a scope.',
23
+ },
24
+ },
25
+ create(context) {
26
+ const [{ scope }] = context.options;
27
+ return {
28
+ Document(node) {
29
+ if (node.body.type !== 'Object') {
30
+ return;
31
+ }
32
+ const nameProperty = node.body.members.find((member) => member.name.type === 'String' && member.name.value === 'name');
33
+ if (nameProperty?.value.type !== 'String') {
34
+ return;
35
+ }
36
+ const packageName = nameProperty.value.value;
37
+ if (scope === false && packageName.startsWith('@')) {
38
+ context.report({
39
+ node: nameProperty.value,
40
+ messageId: 'forbidPackageScope',
41
+ });
42
+ }
43
+ else if (scope && !packageName.startsWith(`@${scope}/`)) {
44
+ context.report({
45
+ node: nameProperty.value,
46
+ messageId: 'requirePackageScope',
47
+ data: { scope },
48
+ });
49
+ }
50
+ },
51
+ };
52
+ },
53
+ };
54
+ export default rule;
@@ -11,8 +11,8 @@ interface PathGroup {
11
11
  isSideEffect?: boolean;
12
12
  }
13
13
  export interface Options {
14
- groups: ReadonlyArray<Arrayable<ImportType>>;
15
- pathGroups: PathGroup[];
14
+ groups?: ReadonlyArray<Arrayable<ImportType>>;
15
+ pathGroups?: PathGroup[];
16
16
  }
17
17
  type MessageId = 'error' | 'order' | 'noLineBetweenImports';
18
18
  declare const _default: TSESLint.RuleModule<MessageId, [Options], unknown, TSESLint.RuleListener>;
@@ -536,12 +536,12 @@ export default createRule({
536
536
  const tsConfigPaths = loadConfig(settings)?.config.compilerOptions?.paths ?? {};
537
537
  let ranks;
538
538
  try {
539
- const { pathGroups, maxPosition } = convertPathGroupsForRanks(options.pathGroups, Object.keys(tsConfigPaths));
539
+ const { pathGroups, maxPosition } = convertPathGroupsForRanks(options.pathGroups ?? [], Object.keys(tsConfigPaths));
540
540
  const types = new Set(baseTypes);
541
541
  pathGroups.forEach((group) => {
542
542
  types.add(group.group);
543
543
  });
544
- const { groups, omittedTypes } = convertGroupsToRanks(['sideEffect', ...options.groups], types, settings['mrpalmer/coreModules']);
544
+ const { groups, omittedTypes } = convertGroupsToRanks(['sideEffect', ...(options.groups ?? defaultGroups)], types, settings['mrpalmer/coreModules']);
545
545
  ranks = {
546
546
  groups,
547
547
  omittedTypes,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrpalmer/eslint-plugin",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Custom ESLint rules for Mike Palmer's projects",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,6 +21,7 @@
21
21
  "minimatch": "^10.0.1"
22
22
  },
23
23
  "peerDependencies": {
24
+ "@eslint/json": "^0.14.0",
24
25
  "@typescript-eslint/utils": "^8.0.0",
25
26
  "eslint": "^9.0.0"
26
27
  },