jsegd-fluig-lint
v1.0.0
Published
Plugin de lint para projetos Fluig utilizando ESLint.
Readme
jsegd-fluig-lint
Plugin ESLint para validar código TypeScript compatível com Rhino (Java 11) executado na plataforma Fluig.
🎯 Objetivo
O Fluig utiliza o Rhino (engine JavaScript do Java) para executar código TypeScript transpilado. O Rhino possui limitações em relação ao JavaScript moderno (ES6+), e este plugin ajuda a identificar padrões incompatíveis durante o desenvolvimento, evitando erros em tempo de execução.
📦 Instalação
npm install jsegd-fluig-lint --save-devou com yarn:
yarn add -D jsegd-fluig-lintou com pnpm:
pnpm add -D jsegd-fluig-lint🚀 Uso com ESLint (ESM)
Configuração Recomendada (Mais Simples)
Crie ou edite o arquivo eslint.config.js (formato ESM):
import jsegdFluigLint from "jsegd-fluig-lint";
export default [
{
plugins: {
"jsegd-fluig-lint": jsegdFluigLint,
},
},
...jsegdFluigLint.configs.recommended,
];Esta configuração já inclui todas as regras necessárias, separadas por tipo de arquivo (.ts e .d.ts).
Configuração com TypeScript ESLint
Se você já usa typescript-eslint, pode combinar as configurações:
import globals from "globals";
import tseslint from "typescript-eslint";
import jsegdFluigLint from "jsegd-fluig-lint";
export default [
{ languageOptions: { globals: globals.browser } },
...tseslint.configs.recommended,
// ✅ Plugin jsegd-fluig-lint aplicado apenas em pastas específicas
{
files: [
"workflow/scripts/**/*.{js,mjs,cjs,ts}",
"mechanisms/**/*.{js,mjs,cjs,ts}",
"events/**/*.{js,mjs,ccs,ts}",
"datasets/**/*.{js,mjs,cjs,ts}",
"forms/*/events/**/*.{js,mjs,cjs,ts}",
],
plugins: {
"jsegd-fluig-lint": jsegdFluigLint,
},
...jsegdFluigLint.configs.recommended[0],
},
];Configuração Manual Completa
Se preferir configurar manualmente todas as regras:
import jsegdFluigLint from "jsegd-fluig-lint";
export default [
{
plugins: {
"jsegd-fluig-lint": jsegdFluigLint,
},
},
{
files: [
"workflow/scripts/**/*.{js,mjs,cjs,ts}",
"mechanisms/**/*.{js,mjs,cjs,ts}",
"events/**/*.{js,mjs,ccs,ts}",
"datasets/**/*.{js,mjs,cjs,ts}",
"forms/*/events/**/*.{js,mjs,cjs,ts}",
],
rules: {
"jsegd-fluig-lint/no-strict-equality": "error",
"jsegd-fluig-lint/no-arrow-functions": "error",
"jsegd-fluig-lint/no-modern-es": "error",
"jsegd-fluig-lint/no-optional-chaining": "error",
},
},
{
files: [
"workflow/scripts/**/*.{js,mjs,cjs,ts}",
"mechanisms/**/*.{js,mjs,cjs,ts}",
"events/**/*.{js,mjs,ccs,ts}",
"datasets/**/*.{js,mjs,cjs,ts}",
"forms/*/events/**/*.{js,mjs,cjs,ts}",
],
rules: {
"jsegd-fluig-lint/only-declare-namespace": "error",
"jsegd-fluig-lint/no-promises": "error",
"jsegd-fluig-lint/no-generics": "error",
"jsegd-fluig-lint/no-union-types": "error",
"jsegd-fluig-lint/no-optional": "error",
},
},
];📋 Regras Disponíveis
Para Runtime Rhino (arquivos .ts)
no-strict-equality
Proíbe o uso de === e !==, que não funcionam corretamente na interoperabilidade Java ↔ JavaScript no Rhino.
// ❌ Errado
if (value === null) {
}
// ✅ Correto
if (value == null) {
}no-arrow-functions
Proíbe arrow functions, que não funcionam corretamente com interop Java no Rhino.
// ❌ Errado
const fn = () => console.log("test");
// ✅ Correto
function fn() {
console.log("test");
}no-modern-es
Proíbe o uso de tipos e estruturas modernas do JavaScript (ES6+) não suportadas pelo Rhino:
Map,Set,WeakMap,WeakSetSymbol,BigInt
// ❌ Errado
const map = new Map();
const set = new Set();
// ✅ Correto - Use objetos simples
const map = {};
const set = [];no-optional-chaining
Proíbe optional chaining (?.), não suportado pelo Rhino.
// ❌ Errado
const name = user?.profile?.name;
fn?.();
// ✅ Correto
const name = user && user.profile && user.profile.name;
if (fn) fn();Para Contratos TypeScript (arquivos .d.ts)
only-declare-namespace
Exige que namespaces sejam declarados com declare.
// ❌ Errado
namespace MyNamespace {}
// ✅ Correto
declare namespace MyNamespace {}no-promises
Proíbe o uso de Promise em contratos Rhino.
// ❌ Errado
function fetchData(): Promise<Data>;
// ✅ Correto
function fetchData(): Data;no-generics
Proíbe o uso de generics em contratos Rhino.
// ❌ Errado
function process<T>(data: T): T;
// ✅ Correto
function process(data: any): any;no-union-types
Proíbe union types em contratos Rhino.
// ❌ Errado
function getValue(): string | number;
// ✅ Correto
function getValue(): any;no-optional
Proíbe campos e parâmetros opcionais (?) em contratos Rhino.
// ❌ Errado
interface User {
name?: string;
}
// ✅ Correto
interface User {
name: string;
}🔧 Scripts package.json
Adicione scripts úteis ao seu package.json:
{
"scripts": {
"lint": "eslint .",
"lint:fix": "eslint . --fix"
}
}📄 Licença
Consulte o arquivo LICENSE.md para mais detalhes.
Desenvolvido com ❤️ pela EGD Tecnologia
