-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: Implement eslint rules to move style prop in the bottom of the…
… class (#615) * setup * format styles
- Loading branch information
1 parent
bb839af
commit fdb6c84
Showing
87 changed files
with
4,157 additions
and
4,056 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
/** @type {import('eslint').Rule.RuleModule} */ | ||
'uui-class-prefix': { | ||
meta: { | ||
type: 'problem', | ||
docs: { | ||
description: | ||
'Ensure that all class declarations are prefixed with "UUI"', | ||
category: 'Best Practices', | ||
recommended: true, | ||
}, | ||
schema: [], | ||
}, | ||
create: function (context) { | ||
function checkClassName(node) { | ||
if (node.id && node.id.name && !node.id.name.startsWith('UUI')) { | ||
context.report({ | ||
node: node.id, | ||
message: 'Class declaration should be prefixed with "UUI"', | ||
}); | ||
} | ||
} | ||
|
||
return { | ||
ClassDeclaration: checkClassName, | ||
}; | ||
}, | ||
}, | ||
|
||
/** @type {import('eslint').Rule.RuleModule}*/ | ||
'prefer-static-styles-last': { | ||
meta: { | ||
type: 'suggestion', | ||
docs: { | ||
description: | ||
'Enforce the "styles" property with the static modifier to be the last property of a class that ends with "Element".', | ||
category: 'Best Practices', | ||
recommended: true, | ||
}, | ||
fixable: 'code', | ||
schema: [], | ||
}, | ||
create: function (context) { | ||
return { | ||
ClassDeclaration(node) { | ||
const className = node.id.name; | ||
if (className.endsWith('Element')) { | ||
const staticStylesProperty = node.body.body.find(bodyNode => { | ||
return ( | ||
bodyNode.type === 'PropertyDefinition' && | ||
bodyNode.key.name === 'styles' && | ||
bodyNode.static | ||
); | ||
}); | ||
if (staticStylesProperty) { | ||
const lastProperty = node.body.body[node.body.body.length - 1]; | ||
if (lastProperty.key.name !== staticStylesProperty.key.name) { | ||
context.report({ | ||
node: staticStylesProperty, | ||
message: | ||
'The "styles" property should be the last property of a class declaration.', | ||
data: { | ||
className: className, | ||
}, | ||
fix: function (fixer) { | ||
const sourceCode = context.getSourceCode(); | ||
const staticStylesPropertyText = | ||
sourceCode.getText(staticStylesProperty); | ||
return [ | ||
fixer.replaceTextRange(staticStylesProperty.range, ''), | ||
fixer.insertTextAfterRange( | ||
lastProperty.range, | ||
'\n \n ' + staticStylesPropertyText | ||
), | ||
]; | ||
}, | ||
}); | ||
} | ||
} | ||
} | ||
}, | ||
}; | ||
}, | ||
}, | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.