-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implemented a rule to forbid the export of symbols #1729
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { name, version } = require("./package.json"); | ||
module.exports = { | ||
meta: { | ||
name: name, | ||
version: version, | ||
}, | ||
rules: { | ||
"no-export-symbol": require("./rules/no-export-symbol"), | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "@tact-lang/eslint-plugin-local-rules", | ||
"version": "0.0.0", | ||
"private": true, | ||
"main": "index.js" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const ts = require("typescript"); | ||
|
||
module.exports = { | ||
meta: { | ||
type: "problem", | ||
docs: { | ||
url: "https://github.com/tact-lang/tact/issues/1695", | ||
recommended: true, | ||
}, | ||
}, | ||
|
||
create(context) { | ||
const parserServices = context.sourceCode.parserServices; | ||
const checker = parserServices.program.getTypeChecker(); | ||
|
||
return { | ||
ExportSpecifier(node) { | ||
const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node); | ||
const type = checker.getTypeAtLocation(tsNode); | ||
|
||
if (!isSymbolType(type)) { | ||
return; | ||
} | ||
|
||
const name = context.sourceCode.getText(node); | ||
context.report({ | ||
node, | ||
message: "Forbidden to export the '{{name}}' symbol", | ||
data: { name }, | ||
}); | ||
}, | ||
}; | ||
|
||
function isSymbolType(type) { | ||
const flags = type.getFlags(); | ||
return flags === ts.TypeFlags.UniqueESSymbol; | ||
} | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const exampleSymbol = Symbol("example"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The primary reason I postponed doing this is that I remember there was an official template for eslint rule definitions, and I couldn't find it. It required positive tests, negative tests and documentation, and also rules were implemented in TypeScript. It's nice to have this error message in CI, but Finding/making the rule template is considerably more important :/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
export { exampleSymbol }; // error: Forbidden to export the 'exampleSymbol' symbol | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A scary experiment, but we have #1045 and have to start somewhere...