@rushstack/eslint-plugin-packlets 0.5.0 → 0.6.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/circular-deps.d.ts.map +1 -1
- package/lib/circular-deps.js +1 -0
- package/lib/circular-deps.js.map +1 -1
- package/lib/mechanics.d.ts.map +1 -1
- package/lib/mechanics.js +1 -0
- package/lib/mechanics.js.map +1 -1
- package/lib/readme.d.ts.map +1 -1
- package/lib/readme.js +1 -0
- package/lib/readme.js.map +1 -1
- package/package.json +8 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circular-deps.d.ts","sourceRoot":"","sources":["../src/circular-deps.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAkB,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAOhG,oBAAY,UAAU,GAAG,iBAAiB,CAAC;AAC3C,aAAK,OAAO,GAAG,EAAE,CAAC;AAElB,QAAA,MAAM,YAAY,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"circular-deps.d.ts","sourceRoot":"","sources":["../src/circular-deps.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAkB,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAOhG,oBAAY,UAAU,GAAG,iBAAiB,CAAC;AAC3C,aAAK,OAAO,GAAG,EAAE,CAAC;AAElB,QAAA,MAAM,YAAY,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CA2E1D,CAAC;AAEF,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
package/lib/circular-deps.js
CHANGED
|
@@ -8,6 +8,7 @@ const PackletAnalyzer_1 = require("./PackletAnalyzer");
|
|
|
8
8
|
const DependencyAnalyzer_1 = require("./DependencyAnalyzer");
|
|
9
9
|
const Path_1 = require("./Path");
|
|
10
10
|
const circularDeps = {
|
|
11
|
+
defaultOptions: [],
|
|
11
12
|
meta: {
|
|
12
13
|
type: 'problem',
|
|
13
14
|
messages: { 'circular-import': 'Packlet imports create a circular reference:\n{{report}}' },
|
package/lib/circular-deps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circular-deps.js","sourceRoot":"","sources":["../src/circular-deps.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAM3D,8EAAoE;AAEpE,uDAAoD;AACpD,6DAA0E;AAC1E,iCAA8B;AAK9B,MAAM,YAAY,GAA6C;IAC7D,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,EAAE,iBAAiB,EAAE,0DAA0D,EAAE;QAC3F,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,kDAAkD;YAC/D,4DAA4D;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,MAAM;YACnB,GAAG,EAAE,iEAAiE;SAC1C;KAC/B;IAED,MAAM,EAAE,CAAC,OAAkD,EAAE,EAAE;QAC7D,gEAAgE;QAChE,MAAM,aAAa,GAAW,OAAO,CAAC,WAAW,EAAE,CAAC;QAEpD,6CAA6C;QAC7C,MAAM,OAAO,GAAe,gCAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;QAC3E,MAAM,gBAAgB,GAAuB,OAAO,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,CAAW,CAAC;QAEtG,MAAM,eAAe,GAAoB,iCAAe,CAAC,gBAAgB,CACvE,aAAa,EACb,gBAAgB,CACjB,CAAC;QACF,IAAI,eAAe,CAAC,WAAW,EAAE;YAC/B,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,mGAAmG;YACnG,yGAAyG;YACzG,gDAAgD;YAChD,OAAO,EAAE,CAAC,IAAmB,EAAQ,EAAE;gBACrC,IAAI,eAAe,CAAC,YAAY,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;oBAC1D,MAAM,cAAc,GAClB,uCAAkB,CAAC,gCAAgC,CACjD,eAAe,CAAC,oBAAqB,EACrC,eAAe,EACf,OAAO,CACR,CAAC;oBAEJ,IAAI,cAAc,EAAE;wBAClB,MAAM,kBAAkB,GAAW,WAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;wBAElE,MAAM,oBAAoB,GAAa,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;wBAEhF,wGAAwG;wBACxG,4EAA4E;wBAC5E,oBAAoB,CAAC,IAAI,EAAE,CAAC;wBAC5B,IAAI,oBAAoB,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,oBAAoB,EAAE;4BACpE,IAAI,MAAM,GAAW,EAAE,CAAC;4BACxB,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;gCAC1C,MAAM,QAAQ,GAAW,WAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;gCACvF,MAAM,IAAI,IAAI,aAAa,CAAC,WAAW,sBAAsB,QAAQ,IAAI,CAAC;6BAC3E;4BAED,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,IAAI;gCACV,SAAS,EAAE,iBAAiB;gCAC5B,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;6BACzB,CAAC,CAAC;yBACJ;qBACF;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEO,oCAAY","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as ts from 'typescript';\nimport * as path from 'path';\n\nimport type { ParserServices, TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer } from './PackletAnalyzer';\nimport { DependencyAnalyzer, IPackletImport } from './DependencyAnalyzer';\nimport { Path } from './Path';\n\nexport type MessageIds = 'circular-import';\ntype Options = [];\n\nconst circularDeps: TSESLint.RuleModule<MessageIds, Options> = {\n meta: {\n type: 'problem',\n messages: { 'circular-import': 'Packlet imports create a circular reference:\\n{{report}}' },\n schema: [\n {\n type: 'object',\n additionalProperties: false\n }\n ],\n docs: {\n description: 'Check for circular dependencies between packlets',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n recommended: 'warn',\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const program: ts.Program = ESLintUtils.getParserServices(context).program;\n const tsconfigFilePath: string | undefined = program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n if (packletAnalyzer.nothingToDo) {\n return {};\n }\n\n return {\n // Match the first node in the source file. Ideally we should be matching \"Program > :first-child\"\n // so a warning doesn't highlight the whole file. But that's blocked behind a bug in the query selector:\n // https://github.com/estools/esquery/issues/114\n Program: (node: TSESTree.Node): void => {\n if (packletAnalyzer.isEntryPoint && !packletAnalyzer.error) {\n const packletImports: IPackletImport[] | undefined =\n DependencyAnalyzer.checkEntryPointForCircularImport(\n packletAnalyzer.inputFilePackletName!,\n packletAnalyzer,\n program\n );\n\n if (packletImports) {\n const tsconfigFileFolder: string = Path.dirname(tsconfigFilePath);\n\n const affectedPackletNames: string[] = packletImports.map((x) => x.packletName);\n\n // If 3 different packlets form a circular dependency, we don't need to report the same warning 3 times.\n // Instead, only report the warning for the alphabetically smallest packlet.\n affectedPackletNames.sort();\n if (affectedPackletNames[0] === packletAnalyzer.inputFilePackletName) {\n let report: string = '';\n for (const packletImport of packletImports) {\n const filePath: string = Path.relative(tsconfigFileFolder, packletImport.fromFilePath);\n report += `\"${packletImport.packletName}\" is referenced by ${filePath}\\n`;\n }\n\n context.report({\n node: node,\n messageId: 'circular-import',\n data: { report: report }\n });\n }\n }\n }\n }\n };\n }\n};\n\nexport { circularDeps };\n"]}
|
|
1
|
+
{"version":3,"file":"circular-deps.js","sourceRoot":"","sources":["../src/circular-deps.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAM3D,8EAAoE;AAEpE,uDAAoD;AACpD,6DAA0E;AAC1E,iCAA8B;AAK9B,MAAM,YAAY,GAA6C;IAC7D,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,EAAE,iBAAiB,EAAE,0DAA0D,EAAE;QAC3F,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,kDAAkD;YAC/D,4DAA4D;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,MAAM;YACnB,GAAG,EAAE,iEAAiE;SAC1C;KAC/B;IAED,MAAM,EAAE,CAAC,OAAkD,EAAE,EAAE;QAC7D,gEAAgE;QAChE,MAAM,aAAa,GAAW,OAAO,CAAC,WAAW,EAAE,CAAC;QAEpD,6CAA6C;QAC7C,MAAM,OAAO,GAAe,gCAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;QAC3E,MAAM,gBAAgB,GAAuB,OAAO,CAAC,kBAAkB,EAAE,CAAC,gBAAgB,CAAW,CAAC;QAEtG,MAAM,eAAe,GAAoB,iCAAe,CAAC,gBAAgB,CACvE,aAAa,EACb,gBAAgB,CACjB,CAAC;QACF,IAAI,eAAe,CAAC,WAAW,EAAE;YAC/B,OAAO,EAAE,CAAC;SACX;QAED,OAAO;YACL,mGAAmG;YACnG,yGAAyG;YACzG,gDAAgD;YAChD,OAAO,EAAE,CAAC,IAAmB,EAAQ,EAAE;gBACrC,IAAI,eAAe,CAAC,YAAY,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE;oBAC1D,MAAM,cAAc,GAClB,uCAAkB,CAAC,gCAAgC,CACjD,eAAe,CAAC,oBAAqB,EACrC,eAAe,EACf,OAAO,CACR,CAAC;oBAEJ,IAAI,cAAc,EAAE;wBAClB,MAAM,kBAAkB,GAAW,WAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;wBAElE,MAAM,oBAAoB,GAAa,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;wBAEhF,wGAAwG;wBACxG,4EAA4E;wBAC5E,oBAAoB,CAAC,IAAI,EAAE,CAAC;wBAC5B,IAAI,oBAAoB,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC,oBAAoB,EAAE;4BACpE,IAAI,MAAM,GAAW,EAAE,CAAC;4BACxB,KAAK,MAAM,aAAa,IAAI,cAAc,EAAE;gCAC1C,MAAM,QAAQ,GAAW,WAAI,CAAC,QAAQ,CAAC,kBAAkB,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;gCACvF,MAAM,IAAI,IAAI,aAAa,CAAC,WAAW,sBAAsB,QAAQ,IAAI,CAAC;6BAC3E;4BAED,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,IAAI;gCACV,SAAS,EAAE,iBAAiB;gCAC5B,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;6BACzB,CAAC,CAAC;yBACJ;qBACF;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEO,oCAAY","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type * as ts from 'typescript';\nimport * as path from 'path';\n\nimport type { ParserServices, TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer } from './PackletAnalyzer';\nimport { DependencyAnalyzer, IPackletImport } from './DependencyAnalyzer';\nimport { Path } from './Path';\n\nexport type MessageIds = 'circular-import';\ntype Options = [];\n\nconst circularDeps: TSESLint.RuleModule<MessageIds, Options> = {\n defaultOptions: [],\n meta: {\n type: 'problem',\n messages: { 'circular-import': 'Packlet imports create a circular reference:\\n{{report}}' },\n schema: [\n {\n type: 'object',\n additionalProperties: false\n }\n ],\n docs: {\n description: 'Check for circular dependencies between packlets',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n recommended: 'warn',\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const program: ts.Program = ESLintUtils.getParserServices(context).program;\n const tsconfigFilePath: string | undefined = program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n if (packletAnalyzer.nothingToDo) {\n return {};\n }\n\n return {\n // Match the first node in the source file. Ideally we should be matching \"Program > :first-child\"\n // so a warning doesn't highlight the whole file. But that's blocked behind a bug in the query selector:\n // https://github.com/estools/esquery/issues/114\n Program: (node: TSESTree.Node): void => {\n if (packletAnalyzer.isEntryPoint && !packletAnalyzer.error) {\n const packletImports: IPackletImport[] | undefined =\n DependencyAnalyzer.checkEntryPointForCircularImport(\n packletAnalyzer.inputFilePackletName!,\n packletAnalyzer,\n program\n );\n\n if (packletImports) {\n const tsconfigFileFolder: string = Path.dirname(tsconfigFilePath);\n\n const affectedPackletNames: string[] = packletImports.map((x) => x.packletName);\n\n // If 3 different packlets form a circular dependency, we don't need to report the same warning 3 times.\n // Instead, only report the warning for the alphabetically smallest packlet.\n affectedPackletNames.sort();\n if (affectedPackletNames[0] === packletAnalyzer.inputFilePackletName) {\n let report: string = '';\n for (const packletImport of packletImports) {\n const filePath: string = Path.relative(tsconfigFileFolder, packletImport.fromFilePath);\n report += `\"${packletImport.packletName}\" is referenced by ${filePath}\\n`;\n }\n\n context.report({\n node: node,\n messageId: 'circular-import',\n data: { report: report }\n });\n }\n }\n }\n }\n };\n }\n};\n\nexport { circularDeps };\n"]}
|
package/lib/mechanics.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mechanics.d.ts","sourceRoot":"","sources":["../src/mechanics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAGhF,OAAO,EAAmC,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE3G,oBAAY,UAAU,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AAChE,aAAK,OAAO,GAAG,EAAE,CAAC;AAElB,QAAA,MAAM,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"mechanics.d.ts","sourceRoot":"","sources":["../src/mechanics.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAGhF,OAAO,EAAmC,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE3G,oBAAY,UAAU,GAAG,mBAAmB,GAAG,gBAAgB,CAAC;AAChE,aAAK,OAAO,GAAG,EAAE,CAAC;AAElB,QAAA,MAAM,SAAS,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CAqHvD,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/lib/mechanics.js
CHANGED
package/lib/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ACzB,IAAI,EAAE,IAAI,CAAC,IAAI;6BAChB,CAAC,CAAC;yBACJ;qBACF;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEO,8BAAS","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer, IAnalyzerError, InputFileMessageIds, ImportMessageIds } from './PackletAnalyzer';\n\nexport type MessageIds = InputFileMessageIds | ImportMessageIds;\ntype Options = [];\n\nconst mechanics: TSESLint.RuleModule<MessageIds, Options> = {\n meta: {\n type: 'problem',\n messages: {\n // InputFileMessageIds\n 'file-in-packets-folder': 'The \"packlets\" folder must not contain regular source files',\n 'invalid-packlet-name':\n 'Invalid packlet name \"{{packletName}}\".' +\n ' The name must be lowercase alphanumeric words separated by hyphens. Example: \"my-packlet\"',\n 'misplaced-packlets-folder': 'The packlets folder must be located at \"{{expectedPackletsFolder}}\"',\n 'missing-src-folder': 'Expecting to find a \"src\" folder at: {{srcFolderPath}}',\n 'missing-tsconfig':\n 'In order to use @rushstack/eslint-plugin-packlets, your ESLint config file' +\n ' must configure the TypeScript parser',\n 'packlet-folder-case': 'The packlets folder must be all lower case: {{packletsFolderPath}}',\n\n // ImportMessageIds\n 'bypassed-entry-point':\n 'The import statement does not use the packlet\\'s entry point \"{{entryPointModulePath}}\"',\n 'circular-entry-point': 'Files under a packlet folder must not import from their own index.ts file',\n 'packlet-importing-project-file':\n 'A local project file cannot be imported.' +\n \" A packlet's dependencies must be NPM packages and/or other packlets.\"\n },\n schema: [\n {\n type: 'object',\n additionalProperties: false\n }\n ],\n docs: {\n description: 'Check that file paths and imports follow the basic mechanics for the packlet formalism',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n recommended: 'warn',\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const tsconfigFilePath: string | undefined = ESLintUtils.getParserServices(\n context\n ).program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n if (packletAnalyzer.nothingToDo) {\n return {};\n }\n\n return {\n // Match the first node in the source file. Ideally we should be matching \"Program > :first-child\"\n // so a warning doesn't highlight the whole file. But that's blocked behind a bug in the query selector:\n // https://github.com/estools/esquery/issues/114\n Program: (node: TSESTree.Node): void => {\n if (packletAnalyzer.error) {\n context.report({\n node: node,\n messageId: packletAnalyzer.error.messageId,\n data: packletAnalyzer.error.data\n });\n }\n },\n\n // ImportDeclaration matches these forms:\n // import { X } from '../../packlets/other-packlet';\n // import X from '../../packlets/other-packlet';\n // import type { X, Y } from '../../packlets/other-packlet';\n // import * as X from '../../packlets/other-packlet';\n //\n // ExportNamedDeclaration matches these forms:\n // export { X } from '../../packlets/other-packlet';\n //\n // ExportAllDeclaration matches these forms:\n // export * from '../../packlets/other-packlet';\n // export * as X from '../../packlets/other-packlet';\n 'ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration': (\n node: TSESTree.ImportDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration\n ): void => {\n if (node.source?.type === AST_NODE_TYPES.Literal) {\n if (packletAnalyzer.projectUsesPacklets) {\n // Extract the import/export module path\n // Example: \"../../packlets/other-packlet\"\n const modulePath = node.source.value;\n if (typeof modulePath !== 'string') {\n return;\n }\n\n if (!(modulePath.startsWith('.') || modulePath.startsWith('..'))) {\n // It's not a local import.\n\n // Examples:\n // import { X } from \"npm-package\";\n // import { X } from \"raw-loader!./webpack-file.ts\";\n return;\n }\n\n const lint: IAnalyzerError | undefined = packletAnalyzer.analyzeImport(modulePath);\n if (lint) {\n context.report({\n node: node,\n messageId: lint.messageId,\n data: lint.data\n });\n }\n }\n }\n }\n };\n }\n};\n\nexport { mechanics };\n"]}
|
|
1
|
+
{"version":3,"file":"mechanics.js","sourceRoot":"","sources":["../src/mechanics.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,8EAAoF;AAEpF,uDAA2G;AAK3G,MAAM,SAAS,GAA6C;IAC1D,cAAc,EAAE,EAAE;IAClB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,sBAAsB;YACtB,wBAAwB,EAAE,6DAA6D;YACvF,sBAAsB,EACpB,yCAAyC;gBACzC,4FAA4F;YAC9F,2BAA2B,EAAE,qEAAqE;YAClG,oBAAoB,EAAE,wDAAwD;YAC9E,kBAAkB,EAChB,4EAA4E;gBAC5E,uCAAuC;YACzC,qBAAqB,EAAE,oEAAoE;YAE3F,mBAAmB;YACnB,sBAAsB,EACpB,yFAAyF;YAC3F,sBAAsB,EAAE,2EAA2E;YACnG,gCAAgC,EAC9B,0CAA0C;gBAC1C,uEAAuE;SAC1E;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,KAAK;aAC5B;SACF;QACD,IAAI,EAAE;YACJ,WAAW,EAAE,wFAAwF;YACrG,4DAA4D;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,WAAW,EAAE,MAAM;YACnB,GAAG,EAAE,iEAAiE;SAC1C;KAC/B;IAED,MAAM,EAAE,CAAC,OAAkD,EAAE,EAAE;QAC7D,gEAAgE;QAChE,MAAM,aAAa,GAAW,OAAO,CAAC,WAAW,EAAE,CAAC;QAEpD,6CAA6C;QAC7C,MAAM,gBAAgB,GAAuB,gCAAW,CAAC,iBAAiB,CACxE,OAAO,CACR,CAAC,OAAO,CAAC,kBAAkB,E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e,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;wBACnF,IAAI,IAAI,EAAE;4BACR,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,IAAI;gCACV,SAAS,EAAE,IAAI,CAAC,SAAS;gCACzB,IAAI,EAAE,IAAI,CAAC,IAAI;6BAChB,CAAC,CAAC;yBACJ;qBACF;iBACF;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC;AAEO,8BAAS","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { AST_NODE_TYPES, ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer, IAnalyzerError, InputFileMessageIds, ImportMessageIds } from './PackletAnalyzer';\n\nexport type MessageIds = InputFileMessageIds | ImportMessageIds;\ntype Options = [];\n\nconst mechanics: TSESLint.RuleModule<MessageIds, Options> = {\n defaultOptions: [],\n meta: {\n type: 'problem',\n messages: {\n // InputFileMessageIds\n 'file-in-packets-folder': 'The \"packlets\" folder must not contain regular source files',\n 'invalid-packlet-name':\n 'Invalid packlet name \"{{packletName}}\".' +\n ' The name must be lowercase alphanumeric words separated by hyphens. Example: \"my-packlet\"',\n 'misplaced-packlets-folder': 'The packlets folder must be located at \"{{expectedPackletsFolder}}\"',\n 'missing-src-folder': 'Expecting to find a \"src\" folder at: {{srcFolderPath}}',\n 'missing-tsconfig':\n 'In order to use @rushstack/eslint-plugin-packlets, your ESLint config file' +\n ' must configure the TypeScript parser',\n 'packlet-folder-case': 'The packlets folder must be all lower case: {{packletsFolderPath}}',\n\n // ImportMessageIds\n 'bypassed-entry-point':\n 'The import statement does not use the packlet\\'s entry point \"{{entryPointModulePath}}\"',\n 'circular-entry-point': 'Files under a packlet folder must not import from their own index.ts file',\n 'packlet-importing-project-file':\n 'A local project file cannot be imported.' +\n \" A packlet's dependencies must be NPM packages and/or other packlets.\"\n },\n schema: [\n {\n type: 'object',\n additionalProperties: false\n }\n ],\n docs: {\n description: 'Check that file paths and imports follow the basic mechanics for the packlet formalism',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n recommended: 'warn',\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const tsconfigFilePath: string | undefined = ESLintUtils.getParserServices(\n context\n ).program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n if (packletAnalyzer.nothingToDo) {\n return {};\n }\n\n return {\n // Match the first node in the source file. Ideally we should be matching \"Program > :first-child\"\n // so a warning doesn't highlight the whole file. But that's blocked behind a bug in the query selector:\n // https://github.com/estools/esquery/issues/114\n Program: (node: TSESTree.Node): void => {\n if (packletAnalyzer.error) {\n context.report({\n node: node,\n messageId: packletAnalyzer.error.messageId,\n data: packletAnalyzer.error.data\n });\n }\n },\n\n // ImportDeclaration matches these forms:\n // import { X } from '../../packlets/other-packlet';\n // import X from '../../packlets/other-packlet';\n // import type { X, Y } from '../../packlets/other-packlet';\n // import * as X from '../../packlets/other-packlet';\n //\n // ExportNamedDeclaration matches these forms:\n // export { X } from '../../packlets/other-packlet';\n //\n // ExportAllDeclaration matches these forms:\n // export * from '../../packlets/other-packlet';\n // export * as X from '../../packlets/other-packlet';\n 'ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration': (\n node: TSESTree.ImportDeclaration | TSESTree.ExportNamedDeclaration | TSESTree.ExportAllDeclaration\n ): void => {\n if (node.source?.type === AST_NODE_TYPES.Literal) {\n if (packletAnalyzer.projectUsesPacklets) {\n // Extract the import/export module path\n // Example: \"../../packlets/other-packlet\"\n const modulePath = node.source.value;\n if (typeof modulePath !== 'string') {\n return;\n }\n\n if (!(modulePath.startsWith('.') || modulePath.startsWith('..'))) {\n // It's not a local import.\n\n // Examples:\n // import { X } from \"npm-package\";\n // import { X } from \"raw-loader!./webpack-file.ts\";\n return;\n }\n\n const lint: IAnalyzerError | undefined = packletAnalyzer.analyzeImport(modulePath);\n if (lint) {\n context.report({\n node: node,\n messageId: lint.messageId,\n data: lint.data\n });\n }\n }\n }\n }\n };\n }\n};\n\nexport { mechanics };\n"]}
|
package/lib/readme.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAKhF,oBAAY,UAAU,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AACtF,aAAK,OAAO,GAAG;IACb;QACE,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B;CACF,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"readme.d.ts","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,QAAQ,EAAY,MAAM,uCAAuC,CAAC;AAKhF,oBAAY,UAAU,GAAG,gBAAgB,GAAG,oBAAoB,GAAG,kBAAkB,CAAC;AACtF,aAAK,OAAO,GAAG;IACb;QACE,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B;CACF,CAAC;AAEF,QAAA,MAAM,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,UAAU,EAAE,OAAO,CA8FpD,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
package/lib/readme.js
CHANGED
|
@@ -31,6 +31,7 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
|
|
32
32
|
const PackletAnalyzer_1 = require("./PackletAnalyzer");
|
|
33
33
|
const readme = {
|
|
34
|
+
defaultOptions: [{}],
|
|
34
35
|
meta: {
|
|
35
36
|
type: 'problem',
|
|
36
37
|
messages: {
|
package/lib/readme.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readme.js","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,uCAAyB;AAEzB,8EAAoE;AAEpE,uDAAoD;AASpD,MAAM,MAAM,GAA6C;IACvD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,gBAAgB,EACd,wFAAwF;gBACxF,wCAAwC;YAC1C,kBAAkB,EAChB,iGAAiG;gBACjG,iCAAiC;YACnC,oBAAoB,EAAE,4DAA4D;SACnF;QACD,MAAM,EAAE;YACN;gBACE,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,kBAAkB,EAAE;wBAClB,IAAI,EAAE,QAAQ;qBACf;iBACF;gBACD,oBAAoB,EAAE,KAAK;aAC5B;SACF;QAED,IAAI,EAAE;YACJ,WAAW,EAAE,wFAAwF;YACrG,4DAA4D;YAC5D,QAAQ,EAAE,gBAAgB;YAC1B,4DAA4D;YAC5D,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,iEAAiE;SAC1C;KAC/B;IAED,MAAM,EAAE,CAAC,OAAkD,EAAE,EAAE;;QAC7D,MAAM,kBAAkB,GAAW,CAAA,MAAA,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,0CAAE,kBAAkB,KAAI,EAAE,CAAC;QAEhF,gEAAgE;QAChE,MAAM,aAAa,GAAW,OAAO,CAAC,WAAW,EAAE,CAAC;QAEpD,6CAA6C;QAC7C,MAAM,gBAAgB,GAAuB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;4BACd,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,IAAI;gCACV,SAAS,EAAE,oBAAoB;gCAC/B,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAG,KAAe,CAAC,QAAQ,EAAE,EAAE;6BAChE,CAAC,CAAC;yBACJ;oBACH,CAAC;iBACF,CAAC;aACH;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC;AAEO,wBAAM","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer } from './PackletAnalyzer';\n\nexport type MessageIds = 'missing-readme' | 'error-reading-file' | 'readme-too-short';\ntype Options = [\n {\n minimumReadmeWords?: number;\n }\n];\n\nconst readme: TSESLint.RuleModule<MessageIds, Options> = {\n meta: {\n type: 'problem',\n messages: {\n 'missing-readme':\n 'The ESLint configuration requires each packlet to provide a README.md file summarizing' +\n ' its purpose and usage: {{readmePath}}',\n 'readme-too-short':\n 'The ESLint configuration requires at least {{minimumReadmeWords}} words of documentation in the' +\n ' README.md file: {{readmePath}}',\n 'error-reading-file': 'Error reading input file {{readmePath}}:\\n{{errorMessage}}'\n },\n schema: [\n {\n type: 'object',\n properties: {\n minimumReadmeWords: {\n type: 'number'\n }\n },\n additionalProperties: false\n }\n ],\n\n docs: {\n description: 'Require each packlet folder to have a README.md file summarizing its purpose and usage',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n // Too strict to be recommended in the default configuration\n recommended: false,\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n const minimumReadmeWords: number = context.options[0]?.minimumReadmeWords || 10;\n\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const tsconfigFilePath: string | undefined = ESLintUtils.getParserServices(\n context\n ).program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n\n if (!packletAnalyzer.nothingToDo && !packletAnalyzer.error) {\n if (packletAnalyzer.isEntryPoint) {\n return {\n Program: (node: TSESTree.Node): void => {\n const readmePath: string = path.join(\n packletAnalyzer.packletsFolderPath!,\n packletAnalyzer.inputFilePackletName!,\n 'README.md'\n );\n try {\n if (!fs.existsSync(readmePath)) {\n context.report({\n node: node,\n messageId: 'missing-readme',\n data: { readmePath }\n });\n } else {\n if (minimumReadmeWords > 0) {\n const readmeContent: string = fs.readFileSync(readmePath).toString();\n const words: string[] = readmeContent.split(/[^a-z'\"]+/i).filter((x) => x.length > 0);\n if (words.length < minimumReadmeWords) {\n context.report({\n node: node,\n messageId: 'readme-too-short',\n data: { readmePath, minimumReadmeWords }\n });\n }\n }\n }\n } catch (error) {\n context.report({\n node: node,\n messageId: 'error-reading-file',\n data: { readmePath, errorMessage: (error as Error).toString() }\n });\n }\n }\n };\n }\n }\n\n return {};\n }\n};\n\nexport { readme };\n"]}
|
|
1
|
+
{"version":3,"file":"readme.js","sourceRoot":"","sources":["../src/readme.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,uCAAyB;AAEzB,8EAAoE;AAEpE,uDAAoD;AASpD,MAAM,MAAM,GAA6C;IACvD,cAAc,EAAE,CAAC,EAAE,CAAC;IACpB,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE;YACR,gBAAgB,EACd,wFAAwF;gBACxF,wCAAwC;YAC1C,kBAAkB,EAChB,iGAAiG;gBACjG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AE,IAAI;oCACV,SAAS,EAAE,gBAAgB;oCAC3B,IAAI,EAAE,EAAE,UAAU,EAAE;iCACrB,CAAC,CAAC;6BACJ;iCAAM;gCACL,IAAI,kBAAkB,GAAG,CAAC,EAAE;oCAC1B,MAAM,aAAa,GAAW,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;oCACrE,MAAM,KAAK,GAAa,aAAa,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;oCACtF,IAAI,KAAK,CAAC,MAAM,GAAG,kBAAkB,EAAE;wCACrC,OAAO,CAAC,MAAM,CAAC;4CACb,IAAI,EAAE,IAAI;4CACV,SAAS,EAAE,kBAAkB;4CAC7B,IAAI,EAAE,EAAE,UAAU,EAAE,kBAAkB,EAAE;yCACzC,CAAC,CAAC;qCACJ;iCACF;6BACF;yBACF;wBAAC,OAAO,KAAK,EAAE;4BACd,OAAO,CAAC,MAAM,CAAC;gCACb,IAAI,EAAE,IAAI;gCACV,SAAS,EAAE,oBAAoB;gCAC/B,IAAI,EAAE,EAAE,UAAU,EAAE,YAAY,EAAG,KAAe,CAAC,QAAQ,EAAE,EAAE;6BAChE,CAAC,CAAC;yBACJ;oBACH,CAAC;iBACF,CAAC;aACH;SACF;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAC;AAEO,wBAAM","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport type { TSESLint, TSESTree } from '@typescript-eslint/experimental-utils';\nimport { ESLintUtils } from '@typescript-eslint/experimental-utils';\n\nimport { PackletAnalyzer } from './PackletAnalyzer';\n\nexport type MessageIds = 'missing-readme' | 'error-reading-file' | 'readme-too-short';\ntype Options = [\n {\n minimumReadmeWords?: number;\n }\n];\n\nconst readme: TSESLint.RuleModule<MessageIds, Options> = {\n defaultOptions: [{}],\n meta: {\n type: 'problem',\n messages: {\n 'missing-readme':\n 'The ESLint configuration requires each packlet to provide a README.md file summarizing' +\n ' its purpose and usage: {{readmePath}}',\n 'readme-too-short':\n 'The ESLint configuration requires at least {{minimumReadmeWords}} words of documentation in the' +\n ' README.md file: {{readmePath}}',\n 'error-reading-file': 'Error reading input file {{readmePath}}:\\n{{errorMessage}}'\n },\n schema: [\n {\n type: 'object',\n properties: {\n minimumReadmeWords: {\n type: 'number'\n }\n },\n additionalProperties: false\n }\n ],\n\n docs: {\n description: 'Require each packlet folder to have a README.md file summarizing its purpose and usage',\n // Deprecated in ESLint v8; Keep for backwards compatibility\n category: 'Best Practices',\n // Too strict to be recommended in the default configuration\n recommended: false,\n url: 'https://www.npmjs.com/package/@rushstack/eslint-plugin-packlets'\n } as TSESLint.RuleMetaDataDocs\n },\n\n create: (context: TSESLint.RuleContext<MessageIds, Options>) => {\n const minimumReadmeWords: number = context.options[0]?.minimumReadmeWords || 10;\n\n // Example: /path/to/my-project/src/packlets/my-packlet/index.ts\n const inputFilePath: string = context.getFilename();\n\n // Example: /path/to/my-project/tsconfig.json\n const tsconfigFilePath: string | undefined = ESLintUtils.getParserServices(\n context\n ).program.getCompilerOptions()['configFilePath'] as string;\n\n const packletAnalyzer: PackletAnalyzer = PackletAnalyzer.analyzeInputFile(\n inputFilePath,\n tsconfigFilePath\n );\n\n if (!packletAnalyzer.nothingToDo && !packletAnalyzer.error) {\n if (packletAnalyzer.isEntryPoint) {\n return {\n Program: (node: TSESTree.Node): void => {\n const readmePath: string = path.join(\n packletAnalyzer.packletsFolderPath!,\n packletAnalyzer.inputFilePackletName!,\n 'README.md'\n );\n try {\n if (!fs.existsSync(readmePath)) {\n context.report({\n node: node,\n messageId: 'missing-readme',\n data: { readmePath }\n });\n } else {\n if (minimumReadmeWords > 0) {\n const readmeContent: string = fs.readFileSync(readmePath).toString();\n const words: string[] = readmeContent.split(/[^a-z'\"]+/i).filter((x) => x.length > 0);\n if (words.length < minimumReadmeWords) {\n context.report({\n node: node,\n messageId: 'readme-too-short',\n data: { readmePath, minimumReadmeWords }\n });\n }\n }\n }\n } catch (error) {\n context.report({\n node: node,\n messageId: 'error-reading-file',\n data: { readmePath, errorMessage: (error as Error).toString() }\n });\n }\n }\n };\n }\n }\n\n return {};\n }\n};\n\nexport { readme };\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rushstack/eslint-plugin-packlets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "A lightweight alternative to NPM packages for organizing source files within a single project",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -19,27 +19,26 @@
|
|
|
19
19
|
"typings": "lib/index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@rushstack/tree-pattern": "0.2.4",
|
|
22
|
-
"@typescript-eslint/experimental-utils": "~5.
|
|
22
|
+
"@typescript-eslint/experimental-utils": "~5.38.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@rushstack/heft": "0.
|
|
29
|
-
"@rushstack/heft-node-rig": "1.
|
|
28
|
+
"@rushstack/heft": "0.47.9",
|
|
29
|
+
"@rushstack/heft-node-rig": "1.10.0",
|
|
30
30
|
"@types/eslint": "8.2.0",
|
|
31
31
|
"@types/estree": "0.0.50",
|
|
32
32
|
"@types/heft-jest": "1.0.1",
|
|
33
33
|
"@types/node": "12.20.24",
|
|
34
|
-
"@typescript-eslint/parser": "~5.
|
|
35
|
-
"@typescript-eslint/typescript-estree": "~5.
|
|
34
|
+
"@typescript-eslint/parser": "~5.38.0",
|
|
35
|
+
"@typescript-eslint/typescript-estree": "~5.38.0",
|
|
36
36
|
"eslint": "~8.7.0",
|
|
37
|
-
"typescript": "~4.
|
|
37
|
+
"typescript": "~4.8.4"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "heft build --clean",
|
|
41
41
|
"_phase:build": "heft build --clean",
|
|
42
42
|
"_phase:test": "heft test --no-build"
|
|
43
|
-
}
|
|
44
|
-
"readme": "# @rushstack/eslint-plugin-packlets\n\nPacklets provide a lightweight alternative to NPM packages for organizing source files within a single project. The formalism is validated using ESLint rules.\n\n## Motivation\n\nWhen building a large application, it's a good idea to organize source files into modules, so that their dependencies can be managed. For example, suppose an application's source files can be grouped as follows:\n\n- `src/logging/*.ts` - the logging system\n- `src/data-model/*.ts` - the data model\n- `src/reports/*.ts` - the report engine\n- `src/*.ts` - other arbitrary files such as startup code and the main application\n\nUsing file folders is helpful, but it's not very strict. Files under `src/logging` can easily import files from `/src/reports`, creating a confusing circular import. They can also import arbitrary application files. Also, there is no clear distinction between which files are the \"public API\" for `src/logging` versus its private implementation details.\n\nAll these problems can be solved by reorganizing the project into NPM packages (or [Rush projects](https://rushjs.io/)). Something like this:\n\n- `@my-app/logging` - the logging system\n- `@my-app/data-model` - the data model\n- `@my-app/reports` - the report engine\n- `@my-app/application` - other arbitrary files such as startup code and the main application\n\nHowever, separating code in this way has some downsides. The projects need to build separately, which has some tooling costs (for example, \"watch mode\" now needs to consider multiple projects). In a large monorepo, the library may attract other consumers, before the API has been fully worked out.\n\nPacklets provide a lightweight alternative that offers many of the same benefits of packages, but without the `package.json` file. It's a great way to prototype your project organization before later graduating your packlets into proper NPM packages.\n\n## 5 rules for packlets\n\nWith packlets, our folders would be reorganized as follows:\n\n- `src/packlets/logging/*.ts` - the logging system\n- `src/packlets/data-model/*.ts` - the data model\n- `src/packlets/reports/*.ts` - the report engine\n- `src/*.ts` - other arbitrary files such as startup code and the main application\n\nThe [packlets-tutorial](https://github.com/microsoft/rushstack-samples/tree/main/other/packlets-tutorial) sample project illustrates this layout in full detail.\n\nThe basic design can be summarized in 5 rules:\n\n1. A \"packlet\" is defined to be a folder path `./src/packlets/<packlet-name>/index.ts`. The **index.ts** file will have the exported APIs. The `<packlet-name>` name must consist of lower case words separated by hyphens, similar to an NPM package name.\n\n Example file paths:\n ```\n src/packlets/controls\n src/packlets/logger\n src/packlets/my-long-name\n ```\n\n > **NOTE:** The `packlets` cannot be nested deeper in the tree. Like with NPM packages, `src/packlets` is a flat namespace.\n\n2. Files outside the packlet folder can only import the packlet root **index.ts**:\n\n **src/app/App.ts**\n ```ts\n // Okay\n import { MainReport } from '../packlets/reports';\n\n // Error: The import statement does not use the packlet's entry point (@rushstack/packlets/mechanics)\n import { MainReport } from '../packlets/reports/index';\n\n // Error: The import statement does not use the packlet's entry point (@rushstack/packlets/mechanics)\n import { MainReport } from '../packlets/reports/MainReport';\n ```\n\n3. Files inside a packlet folder should import their siblings directly, not via their own **index.ts** (which might create a circular reference):\n\n **src/packlets/logging/Logger.ts**\n ```ts\n // Okay\n import { MessageType } from \"./MessageType\";\n\n // Error: Files under a packlet folder must not import from their own index.ts file (@rushstack/packlets/mechanics)\n import { MessageType } from \".\";\n\n // Error: Files under a packlet folder must not import from their own index.ts file (@rushstack/packlets/mechanics)\n import { MessageType} from \"./index\";\n ```\n\n\n4. Packlets may reference other packlets, but not in a way that would introduce a circular dependency:\n\n **src/packlets/data-model/DataModel.ts**\n ```ts\n // Okay\n import { Logger } from '../../packlets/logging';\n ```\n\n **src/packlets/logging/Logger.ts**\n ```ts\n // Error: Packlet imports create a circular reference: (@rushstack/packlets/circular-deps)\n // \"logging\" is referenced by src/packlets/data-model/DataModel.ts\n // \"data-model\" is referenced by src/packlets/logging/Logger.ts\n import { DataModel } from '../../packlets/data-model';\n ```\n\n5. Other source files are allowed outside the **src/packlets** folder. They may import a packlet, but packlets must only import from other packlets or NPM packages.\n\n **src/app/App.ts**\n\n ```ts\n // Okay\n import { MainReport } from '../packlets/reports';\n ```\n\n **src/packlets/data-model/ExampleModel.ts**\n ```ts\n // Error: A local project file cannot be imported. A packlet's dependencies must be\n // NPM packages and/or other packlets. (@rushstack/packlets/mechanics)\n import { App } from '../../app/App';\n ```\n\n\n## Getting Started\n\nTo enable packlet validation for a simple `typescript-eslint` setup, reference the `@rushstack/eslint-plugin-packlets` project like this:\n\n**\\<my-project\\>/.eslintrc.js**\n```js\nmodule.exports = {\n root: true,\n parser: '@typescript-eslint/parser',\n plugins: ['@typescript-eslint'],\n extends: [\n 'eslint:recommended',\n 'plugin:@typescript-eslint/recommended',\n 'plugin:@rushstack/eslint-plugin-packlets/recommended' // <--- ADD THIS\n ],\n parserOptions: {\n project: './tsconfig.json',\n sourceType: 'module',\n tsconfigRootDir: __dirname\n }\n};\n```\n\nOr, if you are using the [@rushstack/eslint-config](https://www.npmjs.com/package/@rushstack/eslint-config) ruleset, add the `\"packlets\"` mixin like this:\n\n**\\<my-project\\>/.eslintrc.js**\n```ts\n// This is a workaround for https://github.com/eslint/eslint/issues/3458\nrequire('@rushstack/eslint-config/patch/modern-module-resolution');\n\nmodule.exports = {\n extends: [\n \"@rushstack/eslint-config/profile/node\",\n \"@rushstack/eslint-config/mixins/packlets\" // <--- ADD THIS\n ],\n parserOptions: { tsconfigRootDir: __dirname }\n};\n```\n\nThe `@rushstack/eslint-plugin-packlets` plugin implements three separate rules:\n\n- `@rushstack/packlets/mechanics` - validates most of the import path rules outlined above.\n- `@rushstack/packlets/circular-deps` - detects circular dependencies between packlets. This rule requires an ESLint configuration that enables full type information from the TypeScript compiler.\n- `@rushstack/packlets/readme` - requires each packlet to have a README.md file. This rule is disabled by default.\n\n## Requiring a README.md file\n\nIf you'd like to require a README.md file in each packlet folder, enable the optional `@rushstack/packlets/readme` rule.\n\nThe `minimumReadmeWords` option allows you to specify a minimum number of words of documentation in the README.md file. The default value is `10` words.\n\nExample configuration with the `@rushstack/packlets/readme` rule enabled:\n\n**\\<my-project\\>/.eslintrc.js**\n```ts\n// This is a workaround for https://github.com/eslint/eslint/issues/3458\nrequire('@rushstack/eslint-config/patch/modern-module-resolution');\n\nmodule.exports = {\n extends: [\n \"@rushstack/eslint-config/profile/node\",\n \"@rushstack/eslint-config/mixins/packlets\"\n ],\n parserOptions: { tsconfigRootDir: __dirname },\n overrides: [\n {\n files: ['*.ts', '*.tsx'],\n\n rules: {\n '@rushstack/packlets/readme': [ // <--- ADD THIS\n 'warn',\n { minimumReadmeWords: 10 }\n ]\n }\n }\n ]\n};\n```\n\n## Links\n\n- [CHANGELOG.md](\n https://github.com/microsoft/rushstack/blob/main/stack/eslint-plugin-packlets/CHANGELOG.md) - Find\n out what's new in the latest version\n- [@rushstack/eslint-config](https://www.npmjs.com/package/@rushstack/eslint-config) documentation\n\n`@rushstack/eslint-plugin-packlets` is part of the [Rush Stack](https://rushstack.io/) family of projects.\nThe idea for packlets was originally proposed by [@bartvandenende-wm](https://github.com/bartvandenende-wm)\nand [@victor-wm](https://github.com/victor-wm).\n"
|
|
43
|
+
}
|
|
45
44
|
}
|