## Introduction This PR enables functionality discussed in [Layout Date Formatting](https://github.com/twentyhq/core-team-issues/issues/97). ### TLDR; It enables greater control of date formatting at the object's field level by upgrading all DATE and DATE_TIME fields' settings from: ```ts { displayAsRelativeDate: boolean } ``` to: ```ts type FieldDateDisplayFormat = 'full_date' | 'relative_date' | 'date' | 'time' | 'year' | 'custom' { displayFormat: FieldDateDisplayFormat } ``` PR also includes an upgrade command that will update any existing DATE and DATE_TIME fields to the new settings value --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: Félix Malfait <felix@twenty.com> Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { ESLintUtils, TSESTree } from '@typescript-eslint/utils';
|
|
|
|
// NOTE: The rule will be available in ESLint configs as "@nx/workspace-no-hardcoded-colors"
|
|
export const RULE_NAME = 'no-hardcoded-colors';
|
|
|
|
export const rule = ESLintUtils.RuleCreator(() => __filename)({
|
|
name: RULE_NAME,
|
|
meta: {
|
|
docs: {
|
|
description:
|
|
'Do not use hardcoded RGBA or Hex colors. Please use a color from the theme file.',
|
|
},
|
|
messages: {
|
|
hardcodedColor:
|
|
'Hardcoded color {{ color }} found. Please use a color from the theme file.',
|
|
},
|
|
type: 'suggestion',
|
|
schema: [],
|
|
fixable: 'code',
|
|
},
|
|
defaultOptions: [],
|
|
create: (context) => {
|
|
const testHardcodedColor = (
|
|
literal: TSESTree.Literal | TSESTree.TemplateLiteral,
|
|
) => {
|
|
const colorRegex = /(?:rgba?\()|(?:#[0-9a-fA-F]{3,6})\b/i;
|
|
|
|
if (
|
|
literal.type === TSESTree.AST_NODE_TYPES.Literal &&
|
|
typeof literal.value === 'string'
|
|
) {
|
|
if (colorRegex.test(literal.value)) {
|
|
context.report({
|
|
node: literal,
|
|
messageId: 'hardcodedColor',
|
|
data: {
|
|
color: literal.value,
|
|
},
|
|
});
|
|
}
|
|
} else if (literal.type === TSESTree.AST_NODE_TYPES.TemplateLiteral) {
|
|
const firstStringValue = literal.quasis[0]?.value.raw;
|
|
|
|
if (colorRegex.test(firstStringValue)) {
|
|
context.report({
|
|
node: literal,
|
|
messageId: 'hardcodedColor',
|
|
data: {
|
|
color: firstStringValue,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
};
|
|
|
|
return {
|
|
Literal: testHardcodedColor,
|
|
TemplateLiteral: testHardcodedColor,
|
|
};
|
|
},
|
|
});
|