-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add flat config preset for compiled & fix docs #1727
Changes from all commits
32bdff6
9c4a24e
24bf241
20e4a18
014f25d
62cbb4b
b7825e6
4cdfe7f
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,5 @@ | ||
--- | ||
'@compiled/eslint-plugin': minor | ||
--- | ||
|
||
Adding flat config preset for `@compiled/eslint-plugin` and adding missing descriptions to ESLint rules |
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; |
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; |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,3 +1,4 @@ | ||||||||||||||||
import { flatRecommended } from './configs/flat-recommended'; | ||||||||||||||||
import { recommended } from './configs/recommended'; | ||||||||||||||||
import { jsxPragmaRule } from './rules/jsx-pragma'; | ||||||||||||||||
import { localCXXCSSRule } from './rules/local-cx-xcss'; | ||||||||||||||||
|
@@ -14,6 +15,9 @@ import { noStyledTaggedTemplateExpressionRule } from './rules/no-styled-tagged-t | |||||||||||||||
import { noSuppressXCSS } from './rules/no-suppress-xcss'; | ||||||||||||||||
import { shorthandFirst } from './rules/shorthand-property-sorting'; | ||||||||||||||||
|
||||||||||||||||
export const name = '/* NAME */'; | ||||||||||||||||
export const version = '/* VERSION */'; | ||||||||||||||||
|
||||||||||||||||
export const rules = { | ||||||||||||||||
'jsx-pragma': jsxPragmaRule, | ||||||||||||||||
'local-cx-xcss': localCXXCSSRule, | ||||||||||||||||
|
@@ -29,8 +33,27 @@ export const rules = { | |||||||||||||||
'no-suppress-xcss': noSuppressXCSS, | ||||||||||||||||
'no-empty-styled-expression': noEmptyStyledExpressionRule, | ||||||||||||||||
'shorthand-property-sorting': shorthandFirst, | ||||||||||||||||
}; | ||||||||||||||||
} as const; | ||||||||||||||||
|
||||||||||||||||
export const plugin = { | ||||||||||||||||
meta: { | ||||||||||||||||
name, | ||||||||||||||||
version, | ||||||||||||||||
}, | ||||||||||||||||
rules, | ||||||||||||||||
configs: { | ||||||||||||||||
recommended, | ||||||||||||||||
'flat/recommended': { | ||||||||||||||||
...flatRecommended, | ||||||||||||||||
plugins: { | ||||||||||||||||
get '@compiled'() { | ||||||||||||||||
return plugin; | ||||||||||||||||
}, | ||||||||||||||||
Comment on lines
+49
to
+51
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. This is a bit more coherent than Only real concern is could this ever backfire with some Node support? I feel like it's been around forever but also a syntax I never use (because when it was introduced it wasn't ready to be used)…it's good now, right? Also, would you ever want to merge this though?
Suggested change
|
||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
} as const; | ||||||||||||||||
|
||||||||||||||||
export const configs = plugin.configs; | ||||||||||||||||
|
||||||||||||||||
export const configs = { | ||||||||||||||||
recommended, | ||||||||||||||||
}; | ||||||||||||||||
export default plugin; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import { createNoTaggedTemplateExpressionRule, isKeyframes } from '../../utils'; | |
export const noKeyframesTaggedTemplateExpressionRule: Rule.RuleModule = { | ||
meta: { | ||
docs: { | ||
recommended: true, | ||
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. Adding a few |
||
description: 'Disallows the `keyframes` tagged template expression', | ||
url: 'https://github.com/atlassian-labs/compiled/tree/master/packages/eslint-plugin/src/rules/no-keyframes-tagged-template-expression', | ||
}, | ||
fixable: 'code', | ||
|
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.
thank you ❤️ ❤️ ❤️