β¬ οΈ Back to Table of Contents
π debug-namespace¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 2 |
| π¦ Imports | 3 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin-internal/src/rules/debug-namespace.ts
π€ Default Export¶
| Property | Value |
|---|---|
name |
'debug-namespace' |
meta.type |
'problem' |
meta.docs.description |
'Enforce consistent debug() namespaces based on package name and file path' |
meta.fixable |
'code' |
meta.messages.mismatched |
'debug() namespace should match package and file. Use the fixer to update it.' |
meta.schema |
[] |
defaultOptions |
[] |
Entry point: create β documented under Functions.
π¦ Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
getStaticValue |
@typescript-eslint/utils/ast-utils |
createRule |
../util/index.js |
Functions¶
create(context: any): { 'VariableDeclarator[id.name="log"] > CallExpression[argum⦶
Parameters:
contextany
Returns: { 'VariableDeclarator[id.name="log"] > CallExpression[arguments.length=1][callee.name="debug"]'?: undefined; } | { 'VariableDeclarator[id.name="log"] > CallExpression[arguments.length=1][callee.name="debug"]'(node: TSESTree.CallExpression): void; }
Calls:
filePathToNamespacegetStaticValue (from @typescript-eslint/utils/ast-utils)context.reportfixer.replaceText
Code
create(context) {
const expected = filePathToNamespace(context.filename);
if (!expected) {
return {};
}
return {
'VariableDeclarator[id.name="log"] > CallExpression[arguments.length=1][callee.name="debug"]'(
node: TSESTree.CallExpression,
) {
const [argument] = node.arguments;
const staticValue = getStaticValue(argument);
if (
typeof staticValue?.value !== 'string' ||
staticValue.value === expected
) {
return;
}
context.report({
node: argument,
messageId: 'mismatched',
fix: fixer => fixer.replaceText(argument, `'${expected}'`),
});
},
};
}
filePathToNamespace(filePath: string): string¶
Parameters:
filePathstring
Returns: string
Calls:
filePath .split(/packages[\\/]+/) .slice(1) .joinrelativePath .replace(/^[\\/]/, '') .replace(/(?:dist|lib|src)(\/|\\)/, '') .replace(/\.\w+$/, '') .replaceAll
Code
function filePathToNamespace(filePath: string) {
const relativePath = filePath
.split(/packages[\\/]+/)
.slice(1)
.join('');
const relativeNamespace = relativePath
.replace(/^[\\/]/, '')
.replace(/(?:dist|lib|src)(\/|\\)/, '')
.replace(/\.\w+$/, '')
.replaceAll(/[^a-z0-9-]+/gi, ':');
return `typescript-eslint:${relativeNamespace}`;
}
Generated by Syntax Scribe