0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-06 14:50:21 -05:00

chore: eslint config

This commit is contained in:
Juanfran 2024-03-11 14:57:11 +01:00
parent b535718c0e
commit 92a26457e0
32 changed files with 218 additions and 81 deletions

View file

@ -39,8 +39,63 @@
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@nx/typescript",
"plugin:deprecation/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-unused-vars": ["error"],
"no-multiple-empty-lines": [
2,
{
"max": 1
}
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
]
}
},
{
"files": ["*.spec.ts"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@nx/typescript",
"plugin:deprecation/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-unused-vars": ["error"],
"no-multiple-empty-lines": [
2,
{
"max": 1
}
],
"quotes": [
"error",
"single",
{
"avoidEscape": true
}
],
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@ngrx/prefix-selectors-with-select": "off"
}
},
{
"files": ["*.js", "*.jsx"],

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./apps/contrast-plugin/tsconfig.app.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -1,21 +0,0 @@
import { AppElement } from './app.element';
describe('AppElement', () => {
let app: AppElement;
beforeEach(() => {
app = new AppElement();
});
it('should create successfully', () => {
expect(app).toBeTruthy();
});
it('should have a greeting', () => {
app.connectedCallback();
expect(app.querySelector('h1').innerHTML).toContain(
'Welcome contrast-plugin'
);
});
});

View file

@ -1,3 +1,4 @@
/* eslint-disable */
import 'plugins-styles/lib/styles.css';
import './app.element.css';

View file

@ -8,6 +8,10 @@ penpot.ui.onMessage<{ content: string }>((message) => {
const pageState = penpot.getPageState();
const fileState = penpot.getFileState();
if (!pageState || !fileState) {
return;
}
penpot.ui.sendMessage({
type: 'init',
content: {

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./apps/example-plugin/tsconfig.app.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -1,3 +1,4 @@
/* eslint-disable */
import 'plugins-styles/lib/styles.css';
import './app.element.css';

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./apps/example-styles/tsconfig.app.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./apps/rpc-api/tsconfig.app.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -5,20 +5,20 @@ import AutoLoad from '@fastify/autoload';
/* eslint-disable-next-line */
export interface AppOptions {}
export async function app(fastify: FastifyInstance, opts: AppOptions) {
export function app(fastify: FastifyInstance, opts: AppOptions) {
fastify;
// This loads all plugins defined in plugins
// those should be support plugins that are reused
// through your application
fastify.register(AutoLoad, {
void fastify.register(AutoLoad, {
dir: path.join(__dirname, 'plugins'),
options: { ...opts },
});
// This loads all plugins defined in routes
// define your routes in one of these
fastify.register(AutoLoad, {
void fastify.register(AutoLoad, {
dir: path.join(__dirname, 'routes'),
options: { ...opts },
});

View file

@ -2,6 +2,6 @@ import { FastifyInstance } from 'fastify';
import fp from 'fastify-plugin';
import cors from '@fastify/cors';
export default fp(async function (fastify: FastifyInstance) {
fastify.register(cors);
export default fp(function (fastify: FastifyInstance) {
void fastify.register(cors);
});

View file

@ -7,6 +7,6 @@ import sensible from '@fastify/sensible';
*
* @see https://github.com/fastify/fastify-sensible
*/
export default fp(async function (fastify: FastifyInstance) {
fastify.register(sensible);
export default fp(function (fastify: FastifyInstance) {
void fastify.register(sensible);
});

View file

@ -3,7 +3,7 @@ import { v4 } from 'uuid';
const token = process.env.ACCESS_TOKEN;
export default async function (fastify: FastifyInstance) {
export default function (fastify: FastifyInstance) {
const apiUrl = process.env.API_URL + '/api/rpc/command';
const fakeSessionId = v4();
@ -97,7 +97,8 @@ export default async function (fastify: FastifyInstance) {
)
.then((data) => {
console.log('Success:', data);
reply.send(data);
return reply.send(data);
})
.catch((error) => {
console.error('Error:', error);

View file

@ -10,7 +10,7 @@ const server = Fastify({
});
// Register your application as a normal plugin.
server.register(app);
void server.register(app);
// Start listening.
server.listen({ port, host }, (err) => {

9
docs/create-app-lib.md Normal file
View file

@ -0,0 +1,9 @@
Every time a project or library is created the `typescript-eslint/parser` must be added.
```json
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./apps/app-name/tsconfig.app.json"
},
```

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./libs/plugins-data-parser/tsconfig.lib.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -53,8 +53,8 @@ export interface Option {
position: number;
frameId: string;
id: string;
axis: null | unknown;
x: null | unknown;
axis: unknown;
x: unknown;
}
export interface Components {

View file

@ -38,7 +38,7 @@ export interface CljValues {
export interface UnderscoreValues {
__meta?: null | number;
__extmap?: null | number;
__hash: number | number;
__hash: null | number;
}
export interface NilValues {

View file

@ -121,7 +121,7 @@ export function parseArrProperty(
*/
export function parseObjArr(obj: unknown): unknown {
if (isSingleObjectWithProperty(obj, 'arr')) {
return parseArrProperty((obj as Arr)['arr'] as unknown[]);
return parseArrProperty((obj as Arr)['arr']);
}
return obj;

View file

@ -6,5 +6,9 @@ import { UnparsedSelection } from '../models/selection.model';
export function getSelectedUuids(selection: UnparsedSelection): string[] {
const root = selection?.linked_map?.delegate_map?.root?.arr;
return (root?.filter((r) => r?.uuid).map((r) => r.uuid) as string[]) || [];
if (!root) {
return [];
}
return root.map((r) => r.uuid).filter((uuid): uuid is string => !!uuid);
}

View file

@ -1,27 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"module": "ESNext",
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"types": ["vite/client"],
"noEmit": true,
"lib": ["ESNext", "DOM"],
"skipLibCheck": true,
"esModuleInterop": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": ["src"],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View file

@ -0,0 +1,22 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./libs/plugins-runtime/tsconfig.*?.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -17,21 +17,19 @@ export function initialize(api: any) {
console.log(api);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
/* eslint-disable */
api.addListener('plugin-page', 'page', (page: any) => {
console.log('Page Changed:', page);
setPageState(page);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
api.addListener('plugin-file', 'file', (file: any) => {
console.log('File Changed:', file);
setFileState(file);
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
api.addListener('plugin-selection', 'selection', (selection: any) => {
const selectionData = getSelectedUuids(selection);
console.log('Selection Changed:', selectionData);

View file

@ -99,7 +99,6 @@ describe('Plugin api', () => {
describe('events', () => {
it('invalid event', () => {
expect(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
api.on('invalid' as any, vi.fn());
}).toThrow();
});
@ -109,11 +108,11 @@ describe('Plugin api', () => {
api.on('pagechange', callback);
triggerEvent('pagechange', 'test');
triggerEvent('pagechange', 'test' as any);
api.off('pagechange', callback);
triggerEvent('pagechange', 'test');
triggerEvent('pagechange', 'test' as any);
expect(callback).toHaveBeenCalledWith('test');
expect(callback).toHaveBeenCalledTimes(1);
@ -124,11 +123,11 @@ describe('Plugin api', () => {
api.on('filechange', callback);
triggerEvent('filechange', 'test');
triggerEvent('filechange', 'test' as any);
api.off('filechange', callback);
triggerEvent('filechange', 'test');
triggerEvent('filechange', 'test' as any);
expect(callback).toHaveBeenCalledWith('test');
expect(callback).toHaveBeenCalledTimes(1);
@ -140,11 +139,11 @@ describe('Plugin api', () => {
api.on('selectionchange', callback);
triggerEvent('selectionchange', 'test');
triggerEvent('selectionchange', 'test' as any);
api.off('selectionchange', callback);
triggerEvent('selectionchange', 'test');
triggerEvent('selectionchange', 'test' as any);
expect(callback).toHaveBeenCalledWith('test');
expect(callback).toHaveBeenCalledTimes(1);

View file

@ -1,5 +1,5 @@
export declare global {
declare namespace globalThis {
function ɵloadPlugin(cofig: PluginConfig): void;
function ɵloadPlugin(cofig: PluginConfig): Promise<void>;
}
}

View file

@ -5,7 +5,7 @@ import { PluginConfig } from './models/plugin-config.model';
function loadManifest(url: string): Promise<Manifest> {
return fetch(url)
.then((response) => response.json())
.then((manifest: Manifest) => {
.then((manifest: Manifest): Manifest => {
const parseResult = manifestSchema.safeParse(manifest);
if (!parseResult.success) {
@ -24,7 +24,10 @@ function loadCode(url: string): Promise<string> {
return fetch(url).then((response) => response.text());
}
export async function parseManifest(config: PluginConfig) {
export async function parseManifest(config: PluginConfig): Promise<{
manifest: Manifest;
code: string;
}> {
const manifest = await loadManifest(config.manifest);
const code = await loadCode(manifest.code);

View file

@ -1,6 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"ignorePatterns": ["!**/*", "vite.config.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./libs/plugins-styles/tsconfig.lib.json"
},
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],

View file

@ -1,7 +0,0 @@
import { pluginsCssLib } from './plugins-styles';
describe('pluginsCssLib', () => {
it('should work', () => {
expect(pluginsCssLib()).toEqual('plugins-styles');
});
});

View file

@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/out-tsc",
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node", "vite/client"]
},

45
package-lock.json generated
View file

@ -14,6 +14,7 @@
"dependencies": {
"@fastify/autoload": "~5.7.1",
"@fastify/sensible": "~5.2.0",
"@types/uuid": "^9.0.8",
"axios": "^1.6.0",
"fastify": "~4.13.0",
"fastify-plugin": "~4.5.0",
@ -38,12 +39,13 @@
"@swc/helpers": "~0.5.2",
"@types/node": "20.11.16",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitest/coverage-v8": "1.2.2",
"@vitest/ui": "1.2.2",
"esbuild": "^0.19.2",
"eslint": "~8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-deprecation": "^2.0.0",
"happy-dom": "^13.6.2",
"husky": "^9.0.10",
"jsdom": "~22.1.0",
@ -4290,6 +4292,11 @@
"integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==",
"dev": true
},
"node_modules/@types/uuid": {
"version": "9.0.8",
"resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz",
"integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA=="
},
"node_modules/@types/yargs": {
"version": "17.0.32",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz",
@ -6565,6 +6572,21 @@
"eslint": ">=7.0.0"
}
},
"node_modules/eslint-plugin-deprecation": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/eslint-plugin-deprecation/-/eslint-plugin-deprecation-2.0.0.tgz",
"integrity": "sha512-OAm9Ohzbj11/ZFyICyR5N6LbOIvQMp7ZU2zI7Ej0jIc8kiGUERXPNMfw2QqqHD1ZHtjMub3yPZILovYEYucgoQ==",
"dev": true,
"dependencies": {
"@typescript-eslint/utils": "^6.0.0",
"tslib": "^2.3.1",
"tsutils": "^3.21.0"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0",
"typescript": "^4.2.4 || ^5.0.0"
}
},
"node_modules/eslint-scope": {
"version": "7.2.2",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz",
@ -11445,6 +11467,27 @@
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz",
"integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q=="
},
"node_modules/tsutils": {
"version": "3.21.0",
"resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz",
"integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==",
"dev": true,
"dependencies": {
"tslib": "^1.8.1"
},
"engines": {
"node": ">= 6"
},
"peerDependencies": {
"typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta"
}
},
"node_modules/tsutils/node_modules/tslib": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==",
"dev": true
},
"node_modules/type-check": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",

View file

@ -30,12 +30,13 @@
"@swc/helpers": "~0.5.2",
"@types/node": "20.11.16",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@vitest/coverage-v8": "1.2.2",
"@vitest/ui": "1.2.2",
"esbuild": "^0.19.2",
"eslint": "~8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-deprecation": "^2.0.0",
"happy-dom": "^13.6.2",
"husky": "^9.0.10",
"jsdom": "~22.1.0",
@ -54,6 +55,7 @@
"dependencies": {
"@fastify/autoload": "~5.7.1",
"@fastify/sensible": "~5.2.0",
"@types/uuid": "^9.0.8",
"axios": "^1.6.0",
"fastify": "~4.13.0",
"fastify-plugin": "~4.5.0",