Skip to content

Commit 7212c87

Browse files
authored
refactor: update linting and imports (#322)
* feat: update linting and formatting src folder * feat: update linting and formatting tests folder * refactor: use @utils/ alias import * refactor: use @utils/ alias import | part 2 * refactor: use @src/ and @config/ alias import
1 parent e0688e8 commit 7212c87

File tree

69 files changed

+1073
-884
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1073
-884
lines changed

dist/ui.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/ui.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 138 additions & 78 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"devDependencies": {
3131
"@ctrl/tinycolor": "^3.4.0",
3232
"@emotion/css": "^11.1.3",
33-
"@figma/plugin-typings": "^1.98.0",
33+
"@figma/plugin-typings": "^1.106.0",
3434
"@types/jest": "^28.1.1",
3535
"@types/react": "^18.0.13",
3636
"@types/react-dom": "^18.0.5",
@@ -108,12 +108,50 @@
108108
"browser": true,
109109
"es6": true
110110
},
111+
"parser": "@typescript-eslint/parser",
112+
"parserOptions": {
113+
"project": "./tsconfig.json"
114+
},
115+
"extends": [
116+
"eslint:recommended",
117+
"plugin:@typescript-eslint/recommended"
118+
],
119+
"ignorePatterns": [
120+
"dist",
121+
"node_modules",
122+
"examples",
123+
"tests/**/*.js",
124+
"*.config.js",
125+
"*.d.ts"
126+
],
111127
"rules": {
112128
"default-param-last": 0,
113129
"no-return-assign": 0,
114130
"brace-style": 0,
115131
"no-use-before-define": "off",
116-
"@typescript-eslint/no-use-before-define": "error"
132+
"quotes": [
133+
"error",
134+
"single"
135+
],
136+
"semi": [
137+
"error",
138+
"never"
139+
],
140+
"comma-dangle": [
141+
"error",
142+
"only-multiline"
143+
],
144+
"@typescript-eslint/no-use-before-define": "error",
145+
"@typescript-eslint/ban-ts-comment": "off",
146+
"@typescript-eslint/no-explicit-any": "off",
147+
"@typescript-eslint/no-unused-vars": [
148+
"error",
149+
{
150+
"argsIgnorePattern": "^_",
151+
"varsIgnorePattern": "^_",
152+
"caughtErrorsIgnorePattern": "^_"
153+
}
154+
]
117155
}
118156
},
119157
"jest": {
@@ -142,10 +180,13 @@
142180
],
143181
"moduleNameMapper": {
144182
"^@config/(.*)$": "<rootDir>/src/config/$1",
183+
"^@ui/(.*)$": "<rootDir>/src/ui/$1",
184+
"^@utils/(.*)$": "<rootDir>/src/utilities/$1",
185+
"^@typings/(.*)$": "<rootDir>/types/$1",
145186
"^@src/(.*)$": "<rootDir>/src/$1"
146187
}
147188
},
148189
"dependencies": {
149190
"react-dev-utils": "^12.0.1"
150191
}
151-
}
192+
}

src/extractor/extractBorders.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import extractorInterface from '@typings/extractorInterface'
22
import { borderPropertyInterface } from '@typings/propertyObject'
33
import { StrokeCap, StrokeAlign, PropertyType } from '@typings/valueTypes'
44
import { customTokenNode } from '@typings/tokenNodeTypes'
5-
import roundWithDecimals from '../utilities/roundWithDecimals'
5+
import roundWithDecimals from '@utils/roundWithDecimals'
66
import { tokenTypes } from '@config/tokenTypes'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenCategoryType } from '@typings/tokenCategory'

src/extractor/extractBreakpoints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { breakpointPropertyInterface } from '@typings/propertyObject'
33
import { customTokenNode } from '@typings/tokenNodeTypes'
44
import { UnitTypePixel, PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import roundWithDecimals from '@utils/roundWithDecimals'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenCategoryType } from '@typings/tokenCategory'
99
import { tokenExportKeyType } from '@typings/tokenExportKey'

src/extractor/extractColors.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { colorPropertyInterface, fillValuesType, gradientValuesType } from '@typ
33
import { PaintStyleObject } from '@typings/styles'
44
import { GradientType, PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import { convertPaintToRgba, roundRgba } from '../utilities/convertColor'
7-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import { convertPaintToRgba, roundRgba } from '@utils/convertColor'
7+
import roundWithDecimals from '@utils/roundWithDecimals'
88
import { tokenCategoryType } from '@typings/tokenCategory'
99
import { tokenExportKeyType } from '@typings/tokenExportKey'
1010
import config from '@config/config'
@@ -17,7 +17,7 @@ const transparentFill: fillValuesType = {
1717
}
1818
}
1919

20-
const parseDescription = (description: string = '', aliasArray: string[]) => {
20+
const parseDescription = (description = '', aliasArray: string[]) => {
2121
aliasArray = !aliasArray || aliasArray.filter(i => i).length === 0 ? ['Ref:'] : aliasArray
2222
const regex = new RegExp('(' + aliasArray.join('|').toLowerCase() + ')' + ':?\\s')
2323
// split description in lines
@@ -98,7 +98,7 @@ const extractFills = (paint): fillValuesType | gradientValuesType => {
9898
return null
9999
}
100100

101-
const extractColors: extractorInterface = (tokenNodes: PaintStyleObject[], prefixArray: {color: string[], gradient: string[], alias: string[]}): colorPropertyInterface[] => {
101+
const extractColors: extractorInterface = (tokenNodes: PaintStyleObject[], prefixArray: { color: string[], gradient: string[], alias: string[] }): colorPropertyInterface[] => {
102102
// get all paint styles
103103
return tokenNodes
104104
.reduce((previousValue, node) => {

src/extractor/extractEffects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import extractorInterface from '@typings/extractorInterface'
22
import { effectPropertyInterface } from '@typings/propertyObject'
33
import { EffectType, UnitTypePixel, PropertyType } from '@typings/valueTypes'
44
import { tokenTypes } from '@config/tokenTypes'
5-
import { roundRgba } from '../utilities/convertColor'
5+
import { roundRgba } from '@utils/convertColor'
66
import { tokenCategoryType } from '@typings/tokenCategory'
77
import { tokenExportKeyType } from '@typings/tokenExportKey'
88
import config from '@config/config'
@@ -64,7 +64,7 @@ const extractEffects: extractorInterface = (tokenNodes: EffectStyle[], prefixArr
6464
return tokenNodes
6565
// remove tokens with no grid
6666
.filter(node => node.effects.length > 0)
67-
// build
67+
// build
6868
.map(node => ({
6969
name: `${prefixArray[0]}/${node.name}`,
7070
category: 'effect' as tokenCategoryType,

src/extractor/extractFonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import extractorInterface from '@typings/extractorInterface'
22
import { fontPropertyInterface } from '@typings/propertyObject'
33
import { UnitTypePixel, FontStyle, TextCase, TextDecoration, NumericUnitTypes, PropertyType, FontStretch } from '@typings/valueTypes'
44
import { tokenTypes } from '@config/tokenTypes'
5-
import roundWithDecimals from '../utilities/roundWithDecimals'
5+
import roundWithDecimals from '@utils/roundWithDecimals'
66
import { tokenCategoryType } from '@typings/tokenCategory'
77
import { tokenExportKeyType } from '@typings/tokenExportKey'
88
import config from '@config/config'

src/extractor/extractMotion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { tokenCategoryType } from '@typings/tokenCategory'
88
import { tokenExportKeyType } from '@typings/tokenExportKey'
99
import config from '@config/config'
1010

11-
const direction = (transition: Transition): {} | null => {
11+
const direction = (transition: Transition): object | null => {
1212
if (Object.prototype.hasOwnProperty.call(transition, 'direction')) {
1313
return {
1414
direction: {

src/extractor/extractOpacities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { opacityPropertyInterface } from '@typings/propertyObject'
33
import { customTokenNode } from '@typings/tokenNodeTypes'
44
import { PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import roundWithDecimals from '@utils/roundWithDecimals'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenExportKeyType } from '@typings/tokenExportKey'
99
import { tokenCategoryType } from '@typings/tokenCategory'

src/extractor/extractRadii.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { radiusPropertyInterface } from '@typings/propertyObject'
33
import { customTokenNode } from '@typings/tokenNodeTypes'
44
import { UnitTypePixel, PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import roundWithDecimals from '@utils/roundWithDecimals'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenCategoryType } from '@typings/tokenCategory'
99
import { tokenExportKeyType } from '@typings/tokenExportKey'

src/extractor/extractSizes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sizePropertyInterface } from '@typings/propertyObject'
33
import { customTokenNode } from '@typings/tokenNodeTypes'
44
import { UnitTypePixel, PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import roundWithDecimals from '@utils/roundWithDecimals'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenExportKeyType } from '@typings/tokenExportKey'
99
import { tokenCategoryType } from '@typings/tokenCategory'

src/extractor/extractSpacing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { spacingPropertyInterface } from '@typings/propertyObject'
33
import { customTokenNode } from '@typings/tokenNodeTypes'
44
import { UnitTypePixel, PropertyType } from '@typings/valueTypes'
55
import { tokenTypes } from '@config/tokenTypes'
6-
import roundWithDecimals from '../utilities/roundWithDecimals'
6+
import roundWithDecimals from '@utils/roundWithDecimals'
77
import { filterByPrefix } from './extractUtilities'
88
import { tokenCategoryType } from '@typings/tokenCategory'
99
import { tokenExportKeyType } from '@typings/tokenExportKey'

src/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { getSettings, resetSettings, setSettings } from './utilities/settings'
2-
import { getAccessToken, setAccessToken } from './utilities/accessToken'
1+
import { getSettings, resetSettings, setSettings } from '@utils/settings'
2+
import { getAccessToken, setAccessToken } from '@utils/accessToken'
33
import { Settings as UserSettings } from '@typings/settings'
44
import config from '@config/config'
55
import { commands, PluginCommands } from '@config/commands'
6-
import getVersionDifference from './utilities/getVersionDifference'
7-
import getFileId from './utilities/getFileId'
8-
import { PluginMessage } from '../types/pluginEvent'
9-
import { exportRawTokenArray } from './utilities/getTokenJson'
10-
import { stringifyJson } from './utilities/stringifyJson'
6+
import getVersionDifference from '@utils/getVersionDifference'
7+
import getFileId from '@utils/getFileId'
8+
import { PluginMessage } from '@typings/pluginEvent'
9+
import { exportRawTokenArray } from '@utils/getTokenJson'
10+
import { stringifyJson } from '@utils/stringifyJson'
1111

1212
// initiate UI
1313
figma.showUI(__html__, {
@@ -42,11 +42,11 @@ if ([commands.export, commands.urlExport, commands.generalSettings].includes(fig
4242
}
4343
}
4444
}
45-
46-
if([commands.export, commands.urlExport].includes(figma.command as PluginCommands)) {
47-
postMessageObject.payload.data = stringifyJson(exportRawTokenArray(figma, userSettings));
45+
46+
if ([commands.export, commands.urlExport].includes(figma.command as PluginCommands)) {
47+
postMessageObject.payload.data = stringifyJson(exportRawTokenArray(figma, userSettings))
4848
}
49-
figma.ui.postMessage({...postMessageObject})
49+
figma.ui.postMessage({ ...postMessageObject })
5050
// register the settings UI
5151
figma.ui.show()
5252
}

src/transformer/originalFormatTransformer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { internalTokenInterface, tokenCategoryTypes } from '@typings/propertyObject'
22
import { OriginalFormatTokenInterface } from '@typings/originalFormatProperties'
3-
import { convertRgbaObjectToString } from '../utilities/convertColor'
3+
import { convertRgbaObjectToString } from '@utils/convertColor'
44
import { PropertyType, UnitTypePixel } from '@typings/valueTypes'
55
import config from '@config/config'
66

@@ -154,7 +154,7 @@ const opacityValueTransformer = ({ opacity }) => ({
154154
type: opacity.type
155155
})
156156

157-
const valueTransformer: {} | undefined = {
157+
const valueTransformer: object | undefined = {
158158
size: sizeValueTransformer,
159159
color: defaultValueTransformer,
160160
gradient: defaultValueTransformer,

src/transformer/standardTransformer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { rgbaObjectToHex8 } from '../utilities/convertColor'
1+
import { rgbaObjectToHex8 } from '@utils/convertColor'
22
import { internalTokenInterface } from '@typings/propertyObject'
33
import { StandardTokenInterface, StandardTokenTypes, StandardTokenDataInterface, StandardTokenGroup } from '@typings/standardToken'
4-
import roundWithDecimals from '../utilities/roundWithDecimals'
4+
import roundWithDecimals from '@utils/roundWithDecimals'
55
import { tokenExtensions } from './tokenExtensions'
66
import config from '@config/config'
7-
import { changeNotation } from '../utilities/changeNotation'
7+
import { changeNotation } from '@utils/changeNotation'
88

99
const lineHeightToDimension = (values): number => {
1010
if (values.lineHeight.unit === 'pixel') {
@@ -92,7 +92,7 @@ const fontStyleValueTransformer = ({ values }): StandardTokenDataInterface => ({
9292
}
9393
})
9494

95-
const typographyValueTransformer = ({ name, values }) => ({
95+
const typographyValueTransformer = ({ values }) => ({
9696
fontSize: {
9797
type: 'dimension' as StandardTokenTypes,
9898
value: values.fontSize.value

src/ui/components/FileExportSettings.tsx

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import * as React from 'react'
2-
import { useContext, useRef } from 'react'
3-
import { Button } from '@components/Button'
4-
import { Checkbox } from '@components/Checkbox'
5-
import { Title } from '@components/Title'
6-
import { FigmaContext, SettingsContext, TokenContext } from '@ui/context'
7-
import { css } from '@emotion/css'
8-
import { Footer } from './Footer'
9-
import { downloadJson } from '../modules/downloadJson'
10-
import { prepareExport } from '@src/utilities/prepareExport'
11-
import { Settings } from '@typings/settings'
12-
import { stringifyJson } from '@src/utilities/stringifyJson'
13-
import { Info } from '@components/Info'
14-
import { Row } from '@components/Row'
15-
import { tokenTypes } from '@config/tokenTypes'
16-
import { commands } from '@config/commands'
17-
import { WebLink } from './WebLink'
1+
import * as React from "react";
2+
import { useContext, useRef } from "react";
3+
import { Button } from "@components/Button";
4+
import { Checkbox } from "@components/Checkbox";
5+
import { Title } from "@components/Title";
6+
import { FigmaContext, SettingsContext, TokenContext } from "@ui/context";
7+
import { css } from "@emotion/css";
8+
import { Footer } from "./Footer";
9+
import { downloadJson } from "../modules/downloadJson";
10+
import { prepareExport } from "@utils/prepareExport";
11+
import { Settings } from "@typings/settings";
12+
import { stringifyJson } from "@utils/stringifyJson";
13+
import { Info } from "@components/Info";
14+
import { Row } from "@components/Row";
15+
import { tokenTypes } from "@config/tokenTypes";
16+
import { commands } from "@config/commands";
17+
import { WebLink } from "./WebLink";
1818

1919
const style = css`
2020
display: flex;
@@ -26,13 +26,16 @@ const style = css`
2626
display: grid;
2727
grid-template-columns: repeat(3, 1fr);
2828
}
29-
`
29+
`;
3030

3131
export const FileExportSettings = () => {
32-
const { settings, updateSettings } = useContext<{settings: Settings, updateSettings: any}>(SettingsContext)
33-
const { tokens, setTokens } = useContext(TokenContext)
34-
const { figmaUIApi } = useContext(FigmaContext)
35-
const downloadLinkRef = useRef()
32+
const { settings, updateSettings } = useContext<{
33+
settings: Settings;
34+
updateSettings: any;
35+
}>(SettingsContext);
36+
const { tokens, setTokens } = useContext(TokenContext);
37+
const { figmaUIApi } = useContext(FigmaContext);
38+
const downloadLinkRef = useRef();
3639

3740
React.useEffect(() => {
3841
const { accessToken, ...pluginSettings } = settings;
@@ -50,12 +53,11 @@ export const FileExportSettings = () => {
5053
},
5154
"*"
5255
);
53-
}, [settings]);
54-
56+
}, [settings]);
5557

5658
const handleFormSubmit = (event) => {
57-
event.preventDefault() // Prevent form submit triggering navigation
58-
const exportSettingsForm = event.target
59+
event.preventDefault(); // Prevent form submit triggering navigation
60+
const exportSettingsForm = event.target;
5961
if (exportSettingsForm.checkValidity() === true) {
6062
const { accessToken, ...pluginSettings } = settings;
6163
// save settings to local storage
@@ -98,7 +100,7 @@ export const FileExportSettings = () => {
98100
stringifyJson(tokensToExport, pluginSettings.compression)
99101
);
100102
}
101-
}
103+
};
102104

103105
return (
104106
<form onSubmit={handleFormSubmit} className={style}>
@@ -180,4 +182,4 @@ export const FileExportSettings = () => {
180182
/>
181183
</form>
182184
);
183-
}
185+
};

0 commit comments

Comments
 (0)