mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-29 03:40:57 +00:00
128 lines
5.1 KiB
JavaScript
128 lines
5.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.getGlobalFlatEslintConfiguration = exports.getGlobalEsLintConfiguration = exports.javaScriptOverride = exports.typeScriptOverride = void 0;
|
|
const ast_utils_1 = require("../utils/flat-config/ast-utils");
|
|
/**
|
|
* This configuration is intended to apply to all TypeScript source files.
|
|
* See the eslint-plugin package for what is in the referenced shareable config.
|
|
*/
|
|
exports.typeScriptOverride = {
|
|
files: ['*.ts', '*.tsx'],
|
|
extends: ['plugin:@nx/typescript'],
|
|
/**
|
|
* Having an empty rules object present makes it more obvious to the user where they would
|
|
* extend things from if they needed to
|
|
*/
|
|
rules: {},
|
|
};
|
|
/**
|
|
* This configuration is intended to apply to all JavaScript source files.
|
|
* See the eslint-plugin package for what is in the referenced shareable config.
|
|
*/
|
|
exports.javaScriptOverride = {
|
|
files: ['*.js', '*.jsx'],
|
|
extends: ['plugin:@nx/javascript'],
|
|
/**
|
|
* Having an empty rules object present makes it more obvious to the user where they would
|
|
* extend things from if they needed to
|
|
*/
|
|
rules: {},
|
|
};
|
|
/**
|
|
* This configuration is intended to apply to all "source code" (but not
|
|
* markup like HTML, or other custom file types like GraphQL)
|
|
*/
|
|
const moduleBoundariesOverride = {
|
|
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
rules: {
|
|
'@nx/enforce-module-boundaries': [
|
|
'error',
|
|
{
|
|
enforceBuildableLibDependency: true,
|
|
allow: [],
|
|
depConstraints: [{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] }],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
/**
|
|
* This configuration is intended to apply to all "source code" (but not
|
|
* markup like HTML, or other custom file types like GraphQL)
|
|
*/
|
|
const jestOverride = {
|
|
files: ['*.spec.ts', '*.spec.tsx', '*.spec.js', '*.spec.jsx'],
|
|
env: {
|
|
jest: true,
|
|
},
|
|
rules: {},
|
|
};
|
|
const getGlobalEsLintConfiguration = (unitTestRunner, rootProject) => {
|
|
const config = {
|
|
root: true,
|
|
ignorePatterns: rootProject ? ['!**/*'] : ['**/*'],
|
|
plugins: ['@nx'],
|
|
/**
|
|
* We leverage ESLint's "overrides" capability so that we can set up a root config which will support
|
|
* all permutations of Nx workspaces across all frameworks, libraries and tools.
|
|
*
|
|
* The key point is that we need entirely different ESLint config to apply to different types of files,
|
|
* but we still want to share common config where possible.
|
|
*/
|
|
overrides: [
|
|
...(rootProject ? [] : [moduleBoundariesOverride]),
|
|
exports.typeScriptOverride,
|
|
exports.javaScriptOverride,
|
|
...(unitTestRunner === 'jest' ? [jestOverride] : []),
|
|
],
|
|
};
|
|
return config;
|
|
};
|
|
exports.getGlobalEsLintConfiguration = getGlobalEsLintConfiguration;
|
|
const getGlobalFlatEslintConfiguration = (format, rootProject) => {
|
|
const nodeList = (0, ast_utils_1.createNodeList)(new Map(), [], format);
|
|
let content = (0, ast_utils_1.stringifyNodeList)(nodeList);
|
|
content = (0, ast_utils_1.addImportToFlatConfig)(content, 'nx', '@nx/eslint-plugin');
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/base'), { insertAtTheEnd: false });
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/typescript'));
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatPredefinedConfig)('flat/javascript'));
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
ignores: ['**/dist', '**/out-tsc'],
|
|
}, format));
|
|
if (!rootProject) {
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
files: ['*.ts', '*.tsx', '*.js', '*.jsx'],
|
|
rules: {
|
|
'@nx/enforce-module-boundaries': [
|
|
'error',
|
|
{
|
|
enforceBuildableLibDependency: true,
|
|
allow: [
|
|
// This allows a root project to be present without causing lint errors
|
|
// since all projects will depend on this base file.
|
|
'^.*/eslint(\\.base)?\\.config\\.[cm]?[jt]s$',
|
|
],
|
|
depConstraints: [
|
|
{ sourceTag: '*', onlyDependOnLibsWithTags: ['*'] },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
}, format));
|
|
}
|
|
content = (0, ast_utils_1.addBlockToFlatConfigExport)(content, (0, ast_utils_1.generateFlatOverride)({
|
|
files: [
|
|
'**/*.ts',
|
|
'**/*.tsx',
|
|
'**/*.cts',
|
|
'**/*.mts',
|
|
'**/*.js',
|
|
'**/*.jsx',
|
|
'**/*.cjs',
|
|
'**/*.mjs',
|
|
],
|
|
rules: {},
|
|
}, format));
|
|
return content;
|
|
};
|
|
exports.getGlobalFlatEslintConfiguration = getGlobalFlatEslintConfiguration;
|