Socket
Socket
Sign inDemoInstall

@angular-eslint/schematics

Package Overview
Dependencies
Maintainers
1
Versions
747
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@angular-eslint/schematics - npm Package Compare versions

Comparing version 18.2.1-alpha.6 to 18.2.1-alpha.7

5

dist/add-eslint-to-project/index.d.ts

@@ -0,1 +1,2 @@

import type { Rule } from '@angular-devkit/schematics';
interface Schema {

@@ -5,4 +6,4 @@ project?: string;

}
declare const _default: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
export default _default;
export default function addESLintToProject(schema: Schema): Rule;
export {};
//# sourceMappingURL=index.d.ts.map

31

dist/add-eslint-to-project/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const devkit_imports_1 = require("../devkit-imports");
exports.default = addESLintToProject;
const schematics_1 = require("@angular-devkit/schematics");
const utils_1 = require("../utils");
exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
const projectName = (0, utils_1.determineTargetProjectName)(tree, options.project);
if (!projectName) {
throw new Error('\n' +
`
function addESLintToProject(schema) {
return (tree) => {
const projectName = (0, utils_1.determineTargetProjectName)(tree, schema.project);
if (!projectName) {
throw new Error('\n' +
`
Error: You must specify a project to add ESLint to because you have multiple projects in your angular.json
E.g. npx ng g @angular-eslint/schematics:add-eslint-to-project {{YOUR_PROJECT_NAME_GOES_HERE}}
`.trim());
}
// Create the config file first so that we can check for its existence when setting the target
(0, utils_1.createESLintConfigForProject)(tree, projectName, options.setParserOptionsProject ?? false);
// Update the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(tree, projectName, 'lint');
});
`.trim());
}
return (0, schematics_1.chain)([
// Create the ESLint config file for the project
(0, utils_1.createESLintConfigForProject)(projectName, schema.setParserOptionsProject ?? false),
// Set the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(projectName, 'lint'),
]);
};
}

@@ -0,1 +1,2 @@

import type { Rule } from '@angular-devkit/schematics';
/**

@@ -10,4 +11,4 @@ * We are able to use the full, unaltered Schema directly from @schematics/angular

}
declare const _default: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
export default _default;
export default function (options: Schema): Rule;
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const devkit_imports_1 = require("../devkit-imports");
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const utils_1 = require("../utils");
exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
// Remove angular-eslint specific options before passing to the Angular schematic
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { setParserOptionsProject, ...angularOptions } = options;
const applicationGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'application');
await applicationGenerator(tree, angularOptions);
// Create the config file first so that we can check for its existence when setting the target
(0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
// Update the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
});
function eslintRelatedChanges(options) {
return (0, schematics_1.chain)([
// Create the ESLint config file for the project
(0, utils_1.createESLintConfigForProject)(options.name, options.setParserOptionsProject ?? false),
// Update the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
]);
}
function default_1(options) {
return (host, context) => {
// Remove angular-eslint specific options before passing to the Angular schematic
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { setParserOptionsProject, ...angularOptions } = options;
return (0, schematics_1.chain)([
(0, schematics_1.externalSchematic)('@schematics/angular', 'application', angularOptions),
eslintRelatedChanges(options),
])(host, context);
};
}

@@ -0,1 +1,2 @@

import type { Rule } from '@angular-devkit/schematics';
/**

@@ -10,4 +11,4 @@ * We are able to use the full, unaltered Schema directly from @schematics/angular

}
declare const _default: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
export default _default;
export default function (options: Schema): Rule;
export {};
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const devkit_imports_1 = require("../devkit-imports");
exports.default = default_1;
const schematics_1 = require("@angular-devkit/schematics");
const utils_1 = require("../utils");
exports.default = (0, devkit_imports_1.convertNxGenerator)(async (tree, options) => {
// Remove angular-eslint specific options before passing to the Angular schematic
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { setParserOptionsProject, ...angularOptions } = options;
const libraryGenerator = (0, devkit_imports_1.wrapAngularDevkitSchematic)('@schematics/angular', 'library');
await libraryGenerator(tree, angularOptions);
// Create the config file first so that we can check for its existence when setting the target
(0, utils_1.createESLintConfigForProject)(tree, options.name, options.setParserOptionsProject ?? false);
// Update the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(tree, options.name, 'lint');
});
function eslintRelatedChanges(options) {
return (0, schematics_1.chain)([
// Create the ESLint config file for the project
(0, utils_1.createESLintConfigForProject)(options.name, options.setParserOptionsProject ?? false),
// Update the lint builder and config in angular.json
(0, utils_1.addESLintTargetToProject)(options.name, 'lint'),
]);
}
function default_1(options) {
return (host, context) => {
// Remove angular-eslint specific options before passing to the Angular schematic
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { setParserOptionsProject, ...angularOptions } = options;
return (0, schematics_1.chain)([
(0, schematics_1.externalSchematic)('@schematics/angular', 'library', angularOptions),
eslintRelatedChanges(options),
])(host, context);
};
}
import type { Path } from '@angular-devkit/core';
import type { Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import type { Tree as NxTree } from './devkit-imports';
/**

@@ -27,3 +26,3 @@ * This method is specifically for reading JSON files in a Tree

}): TargetsConfig | null;
export declare function addESLintTargetToProject(tree: NxTree, projectName: string, targetName: 'eslint' | 'lint'): void;
export declare function addESLintTargetToProject(projectName: string, targetName: 'eslint' | 'lint'): Rule;
/**

@@ -57,3 +56,3 @@ * Utility to act on all files in a tree that are not ignored by git.

export declare function createStringifiedRootESLintConfig(prefix: string | null): string;
export declare function createESLintConfigForProject(tree: NxTree, projectName: string, setParserOptionsProject: boolean): void;
export declare function createESLintConfigForProject(projectName: string, setParserOptionsProject: boolean): Rule;
export declare function sortObjectByKeys(obj: Record<string, unknown>): Record<string, unknown>;

@@ -64,3 +63,3 @@ /**

*/
export declare function determineTargetProjectName(tree: NxTree, maybeProject?: string): string | null;
export declare function determineTargetProjectName(tree: Tree, maybeProject?: string): string | null;
/**

@@ -78,4 +77,4 @@ * See `schematicCollections` docs here:

*/
export declare function shouldUseFlatConfig(tree: NxTree | Tree, existingJson?: Record<string, unknown>): boolean;
export declare function shouldUseFlatConfig(tree: Tree, existingJson?: Record<string, unknown>): boolean;
export {};
//# sourceMappingURL=utils.d.ts.map

@@ -24,3 +24,2 @@ "use strict";

const strip_json_comments_1 = __importDefault(require("strip-json-comments"));
const devkit_imports_1 = require("./devkit-imports");
const DEFAULT_PREFIX = 'app';

@@ -76,44 +75,54 @@ /**

}
function offsetFromRoot(fullPathToSourceDir) {
const parts = (0, core_1.normalize)(fullPathToSourceDir).split('/');
let offset = '';
for (let i = 0; i < parts.length; ++i) {
offset += '../';
}
return offset;
}
function serializeJson(json) {
return `${JSON.stringify(json, null, 2)}\n`;
}
function readProjectConfiguration(tree, projectName) {
const angularJSON = (0, devkit_imports_1.readJson)(tree, 'angular.json');
return angularJSON.projects[projectName];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function updateWorkspaceInTree(callback) {
return (host, context) => {
const path = 'angular.json';
host.overwrite(path, serializeJson(callback(readJsonInTree(host, path), context, host)));
return host;
};
}
function updateProjectConfiguration(tree, projectName, projectConfig) {
const angularJSON = (0, devkit_imports_1.readJson)(tree, 'angular.json');
angularJSON.projects[projectName] = projectConfig;
(0, devkit_imports_1.writeJson)(tree, 'angular.json', angularJSON);
}
function addESLintTargetToProject(tree, projectName, targetName) {
const existingProjectConfig = readProjectConfiguration(tree, projectName);
let lintFilePatternsRoot = '';
// Default Angular CLI project at the root of the workspace
if (existingProjectConfig.root === '') {
lintFilePatternsRoot = existingProjectConfig.sourceRoot || 'src';
}
else {
lintFilePatternsRoot = existingProjectConfig.root;
}
const eslintTargetConfig = {
builder: '@angular-eslint/builder:lint',
options: {
lintFilePatterns: [
`${lintFilePatternsRoot}/**/*.ts`,
`${lintFilePatternsRoot}/**/*.html`,
],
},
};
let eslintConfig;
if (existingProjectConfig.root !== '') {
const flatConfigPath = (0, core_1.join)(existingProjectConfig.root, 'eslint.config.js');
if (tree.exists(flatConfigPath)) {
eslintConfig = flatConfigPath;
function addESLintTargetToProject(projectName, targetName) {
return updateWorkspaceInTree((workspaceJson, _, tree) => {
const existingProjectConfig = workspaceJson.projects[projectName];
let lintFilePatternsRoot = '';
// Default Angular CLI project at the root of the workspace
if (existingProjectConfig.root === '') {
lintFilePatternsRoot = existingProjectConfig.sourceRoot || 'src';
}
}
eslintTargetConfig.options.eslintConfig = eslintConfig;
existingProjectConfig.architect = existingProjectConfig.architect || {};
existingProjectConfig.architect[targetName] = eslintTargetConfig;
updateProjectConfiguration(tree, projectName, existingProjectConfig);
else {
lintFilePatternsRoot = existingProjectConfig.root;
}
const eslintTargetConfig = {
builder: '@angular-eslint/builder:lint',
options: {
lintFilePatterns: [
`${lintFilePatternsRoot}/**/*.ts`,
`${lintFilePatternsRoot}/**/*.html`,
],
},
};
let eslintConfig;
if (existingProjectConfig.root !== '') {
const flatConfigPath = (0, core_1.join)(existingProjectConfig.root, 'eslint.config.js');
if (tree.exists(flatConfigPath)) {
eslintConfig = flatConfigPath;
}
}
// TODO: fix
eslintTargetConfig.options.eslintConfig = eslintConfig;
existingProjectConfig.architect = existingProjectConfig.architect || {};
existingProjectConfig.architect[targetName] = eslintTargetConfig;
return workspaceJson;
});
}

@@ -260,3 +269,3 @@ /**

return {
extends: `${(0, devkit_imports_1.offsetFromRoot)(projectRoot)}.eslintrc.json`,
extends: `${offsetFromRoot(projectRoot)}.eslintrc.json`,
ignorePatterns: ['!**/*'],

@@ -294,3 +303,3 @@ overrides: [

const tseslint = require("typescript-eslint");
const rootConfig = require("${(0, devkit_imports_1.offsetFromRoot)(projectRoot)}eslint.config.js");
const rootConfig = require("${offsetFromRoot(projectRoot)}eslint.config.js");

@@ -334,33 +343,38 @@ module.exports = tseslint.config(

}
function createESLintConfigForProject(tree, projectName, setParserOptionsProject) {
const existingProjectConfig = readProjectConfiguration(tree, projectName);
const targets = existingProjectConfig.architect || existingProjectConfig.targets;
const { root: projectRoot, projectType, prefix } = existingProjectConfig;
const hasE2e = !!targets?.e2e;
const useFlatConfig = shouldUseFlatConfig(tree);
const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
/**
* If the root is an empty string it must be the initial project created at the
* root by the Angular CLI's workspace schematic
*/
if (projectRoot === '') {
return createRootESLintConfigFile(tree, prefix || DEFAULT_PREFIX, useFlatConfig);
}
// If, for whatever reason, the root eslint.config.js/.eslintrc.json doesn't exist yet, create it
if (!alreadyHasRootESLintRC && !alreadyHasRootFlatConfig) {
createRootESLintConfigFile(tree, prefix || DEFAULT_PREFIX, useFlatConfig);
}
if (useFlatConfig) {
tree.write((0, core_1.join)((0, core_1.normalize)(projectRoot), 'eslint.config.js'), createStringifiedProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e));
}
else {
(0, devkit_imports_1.writeJson)(tree, (0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), createProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e));
}
function createESLintConfigForProject(projectName, setParserOptionsProject) {
return (tree) => {
const angularJSON = readJsonInTree(tree, 'angular.json');
const { root: projectRoot, projectType, prefix, } = angularJSON.projects[projectName];
const hasE2e = determineTargetProjectHasE2E(angularJSON, projectName);
const useFlatConfig = shouldUseFlatConfig(tree);
const alreadyHasRootFlatConfig = tree.exists('eslint.config.js');
const alreadyHasRootESLintRC = tree.exists('.eslintrc.json');
/**
* If the root is an empty string it must be the initial project created at the
* root by the Angular CLI's workspace schematic
*/
if (projectRoot === '') {
return createRootESLintConfigFile(prefix || DEFAULT_PREFIX, useFlatConfig);
}
const rules = [];
// If, for whatever reason, the root eslint.config.js/.eslintrc.json doesn't exist yet, create it
if (!alreadyHasRootESLintRC && !alreadyHasRootFlatConfig) {
rules.push(createRootESLintConfigFile(prefix || DEFAULT_PREFIX, useFlatConfig));
}
if (useFlatConfig) {
rules.push((tree) => tree.create((0, core_1.join)((0, core_1.normalize)(projectRoot), 'eslint.config.js'), createStringifiedProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e)));
}
else {
rules.push(updateJsonInTree((0, core_1.join)((0, core_1.normalize)(projectRoot), '.eslintrc.json'), () => createProjectESLintConfig(projectRoot, projectType || 'library', prefix || DEFAULT_PREFIX, setParserOptionsProject, hasE2e)));
}
return (0, schematics_1.chain)(rules);
};
}
function createRootESLintConfigFile(tree, prefix, useFlatConfig) {
if (useFlatConfig) {
return tree.write('eslint.config.js', createStringifiedRootESLintConfig(prefix));
}
return (0, devkit_imports_1.writeJson)(tree, '.eslintrc.json', createRootESLintConfig(prefix));
function createRootESLintConfigFile(prefix, useFlatConfig) {
return (tree) => {
if (useFlatConfig) {
return tree.create('eslint.config.js', createStringifiedRootESLintConfig(prefix));
}
return updateJsonInTree('.eslintrc.json', () => createRootESLintConfig(prefix));
};
}

@@ -385,3 +399,3 @@ function sortObjectByKeys(obj) {

}
const workspaceJson = (0, devkit_imports_1.readJson)(tree, 'angular.json');
const workspaceJson = readJsonInTree(tree, 'angular.json');
const projects = Object.keys(workspaceJson.projects);

@@ -394,2 +408,11 @@ if (projects.length === 1) {

/**
* Checking if the target project has e2e setup
* Method will check if angular project architect has e2e configuration to determine if e2e setup
*/
function determineTargetProjectHasE2E(
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
angularJSON, projectName) {
return !!getTargetsConfigFromProject(angularJSON.projects[projectName])?.e2e;
}
/**
* See `schematicCollections` docs here:

@@ -396,0 +419,0 @@ * https://github.com/angular/angular-cli/blob/8431b3f0769b5f95b9e13807a09293d820c4b017/docs/specifications/schematic-collections-config.md

{
"name": "@angular-eslint/schematics",
"version": "18.2.1-alpha.6",
"version": "18.2.1-alpha.7",
"description": "Angular Schematics for angular-eslint",

@@ -39,7 +39,5 @@ "license": "MIT",

"dependencies": {
"@angular-eslint/eslint-plugin": "18.2.1-alpha.6",
"@angular-eslint/eslint-plugin-template": "18.2.1-alpha.6",
"@nx/devkit": ">= 19.5.4 < 20.0.0",
"@angular-eslint/eslint-plugin": "18.2.1-alpha.7",
"@angular-eslint/eslint-plugin-template": "18.2.1-alpha.7",
"ignore": "5.3.2",
"nx": "^19.0.6",
"semver": "7.6.3",

@@ -46,0 +44,0 @@ "strip-json-comments": "3.1.1"

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc