-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(lint): Add linting rule for experimental features
- Loading branch information
Showing
7 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
rules: { | ||
"valid-constructors": require("./rules/valid-constructors"), | ||
"experimental-classes": require("./rules/experimental-classes"), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
RULES: | ||
1. Un-exported classes don't get linted | ||
2. Class name must end with 'Experimental' | ||
The rule is applied to the `experimental` directory. See `.eslintrc.js`. | ||
See ../../../docs/architecture-decision-records/005-x01-package-structure.md | ||
*/ | ||
|
||
const NO_LINT_ERRORS = null; | ||
|
||
module.exports = { | ||
meta: { | ||
type: "suggestion", | ||
docs: { | ||
description: "Signal (potential) un-stability to consumers", | ||
category: "Best Practices", | ||
url: "https://github.com/guardian/cdk/blob/main/docs/architecture-decision-records/005-x01-package-structure.md", | ||
}, | ||
schema: [], | ||
}, | ||
|
||
create(context) { | ||
return { | ||
ClassDeclaration(node) { | ||
const isExported = node.parent.type === "ExportNamedDeclaration"; | ||
|
||
if (!isExported) { | ||
return NO_LINT_ERRORS; | ||
} | ||
|
||
const className = node.id.name; | ||
const isClassNameExperimental = className.endsWith("Experimental"); | ||
|
||
if (isClassNameExperimental) { | ||
return NO_LINT_ERRORS; | ||
} | ||
|
||
return context.report({ | ||
node, | ||
message: `Exported classes should end with 'Experimental' to signal its (potential) un-stability. Rename ${className} to ${className}Experimental.`, | ||
loc: node.loc, | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* This robot is supposed to do helpful things. | ||
* | ||
* @experimental This robot should be helpful, but it might also take over the world... | ||
*/ | ||
export class HelpfulRobotExperimental { | ||
private constructor(task: string) { | ||
console.log(task); | ||
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- testing file | ||
class TheRobot { | ||
private constructor(name: string) { | ||
console.log(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters