-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flat config preset for compiled & fix docs (#1727)
* JFP-1155: Add flat config preset for compiled * JFP-1155: Make recommended property of eslint rule docs match the recommended config * JFP-1155: Fix tsconfig setup for eslint plugin for package.json file * JFP-1155: Add typescript transformer to eslint plugin for name and version * Fix typo in readme Co-authored-by: Grant Wong <[email protected]> --------- Co-authored-by: Grant Wong <[email protected]>
- Loading branch information
1 parent
944518e
commit e8b09ec
Showing
19 changed files
with
189 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@compiled/eslint-plugin': minor | ||
--- | ||
|
||
Adding flat config preset for `@compiled/eslint-plugin` and adding missing descriptions to ESLint rules |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** | ||
* @fileoverview | ||
* This file is a transformer to be used with `ttypescript` to replace the version | ||
* and name of the eslint plugin in the source from the package.json at compile time. | ||
*/ | ||
|
||
// @ts-check | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
const ts = require('typescript'); | ||
|
||
const pkgJson = require('./package.json'); | ||
|
||
/** | ||
* | ||
* @param {ts.Node} node | ||
* @param {string} name | ||
* @param {string} value | ||
* @returns {node is ts.VariableDeclaration & {name: ts.Identifier, initializer: ts.StringLiteral}} | ||
*/ | ||
const isVariableWithProperties = (node, name, value) => | ||
!!( | ||
ts.isVariableDeclaration(node) && | ||
ts.isIdentifier(node.name) && | ||
node.name.text === name && | ||
node.initializer && | ||
ts.isStringLiteral(node.initializer) && | ||
node.initializer.text === value | ||
); | ||
|
||
/** | ||
* @param {ts.Program} _ts | ||
* @returns {ts.TransformerFactory<ts.SourceFile>} | ||
*/ | ||
const transformer = (_ts) => (context) => (sourceFile) => { | ||
/** | ||
* @param {ts.Node} node | ||
* @returns {ts.Node} | ||
*/ | ||
const visitor = (node) => { | ||
if (isVariableWithProperties(node, 'name', '/* NAME */')) { | ||
return ts.factory.updateVariableDeclaration( | ||
node, | ||
node.name, | ||
undefined, | ||
undefined, | ||
ts.factory.createStringLiteral(pkgJson.name) | ||
); | ||
} | ||
|
||
if (isVariableWithProperties(node, 'version', '/* VERSION */')) { | ||
return ts.factory.updateVariableDeclaration( | ||
node, | ||
node.name, | ||
undefined, | ||
undefined, | ||
ts.factory.createStringLiteral(pkgJson.version) | ||
); | ||
} | ||
|
||
return ts.visitEachChild(node, visitor, context); | ||
}; | ||
return ts.visitNode(sourceFile, visitor); | ||
}; | ||
|
||
module.exports = transformer; |
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,16 @@ | ||
export const flatRecommended = { | ||
// plugin is not specified here because flat config needs a reference to the plugin | ||
rules: { | ||
'@compiled/local-cx-xcss': 'error', | ||
'@compiled/no-css-prop-without-css-function': 'error', | ||
'@compiled/no-css-tagged-template-expression': 'error', | ||
'@compiled/no-empty-styled-expression': 'error', | ||
'@compiled/no-exported-css': 'error', | ||
'@compiled/no-exported-keyframes': 'error', | ||
'@compiled/no-invalid-css-map': 'error', | ||
'@compiled/no-js-xcss': 'error', | ||
'@compiled/no-keyframes-tagged-template-expression': 'error', | ||
'@compiled/no-styled-tagged-template-expression': 'error', | ||
'@compiled/no-suppress-xcss': 'error', | ||
}, | ||
} as const; |
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
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
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
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