Socket
Socket
Sign inDemoInstall

@angular-eslint/schematics

Package Overview
Dependencies
Maintainers
1
Versions
740
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 0.7.0-alpha.9 to 0.7.0-alpha.10

dist/convert-tslint-to-eslint/utils.js

190

dist/convert-tslint-to-eslint/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -25,11 +6,9 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.updateObjPropAndRemoveDuplication = exports.updateArrPropAndRemoveDuplication = void 0;
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const tasks_1 = require("@angular-devkit/schematics/tasks");
const eslint_plugin_1 = __importDefault(require("@angular-eslint/eslint-plugin"));
const eslint_plugin_template_1 = __importDefault(require("@angular-eslint/eslint-plugin-template"));
const assert = __importStar(require("assert"));
const utils_1 = require("../utils");
const convert_to_eslint_config_1 = require("./convert-to-eslint-config");
const utils_2 = require("./utils");
const eslintPluginConfigBase = eslint_plugin_1.default.configs.base;

@@ -41,5 +20,3 @@ const eslintPluginConfigRecommended = eslint_plugin_1.default.configs.recommended;

const { root: projectRoot } = utils_1.getProjectConfig(tree, schema.project);
// Existing files
const rootTslintJsonPath = core_1.join(core_1.normalize(tree.root.path), 'tslint.json');
// May or may not exist yet
// May or may not exist yet depending on if this is the root project, or a later one from projects/
const rootEslintrcJsonPath = core_1.join(core_1.normalize(tree.root.path), '.eslintrc.json');

@@ -49,13 +26,5 @@ // Default Angular CLI project at the root of the workspace

return schematics_1.chain([
// Overwrite the "lint" target directly
// Overwrite the "lint" target directly for the selected project in the angular.json
utils_1.addESLintTargetToProject(schema.project, 'lint'),
convertRootTSLintConfig('tslint.json', rootEslintrcJsonPath),
(tree) => {
// This still seems to be generated as an empty file
// TODO: Fix in tslint-to-eslint-config library
const tslintToEslintConfigLogPath = 'tslint-to-eslint-config.log';
if (tree.exists(tslintToEslintConfigLogPath)) {
tree.delete(tslintToEslintConfigLogPath);
}
},
]);

@@ -67,52 +36,6 @@ }

*/
// Existing files
const projectTslintJsonPath = core_1.join(core_1.normalize(projectRoot), 'tslint.json');
// Will be created as part of the chain
const projectEslintrcJsonPath = core_1.join(core_1.normalize(projectRoot), '.eslintrc.json');
/**
* If the root .eslintrc.json does not exist at the time of running the schematic
* this is the first project within the workspace that is being converted.
*
* The addLintFiles() util will handle creating the root .eslintrc.json file with the
* standard global config that Nx creates for all new workspaces.
*
* Therefore we record at this point that this is will be new global config, ready to
* convert the root tslint.json file later on in the chain and merge it with the standard
* Nx root .eslintrc.json contents.
**/
const hasExistingRootEslintrcConfig = tree.exists(rootEslintrcJsonPath);
console.log('rootTslintJsonPath', rootTslintJsonPath);
console.log('projectTslintJsonPath', projectTslintJsonPath);
console.log('rootEslintrcJsonPath', rootEslintrcJsonPath);
console.log('projectEslintrcJsonPath', projectEslintrcJsonPath);
console.log(hasExistingRootEslintrcConfig);
return schematics_1.chain([
// Overwrite the "lint" target directly
utils_1.addESLintTargetToProject(schema.project, 'lint'),
removeExtendsFromProjectTSLint(tree, projectTslintJsonPath),
hasExistingRootEslintrcConfig ? schematics_1.noop() : schematics_1.noop(),
]);
throw new Error('The "convert-tslint-to-eslint" schematic currently only supports single-project Angular CLI workspaces. Multi-project workspace support is coming soon');
};
}
exports.default = convert;
function removeExtendsFromProjectTSLint(tree, projectTslintJsonPath) {
/**
* Remove the relative extends to the root TSLint config before converting,
* otherwise all the root config will be included
*/
// TODO: Extract to function and add unit tests
return utils_1.updateJsonInTree(projectTslintJsonPath, (json) => {
if (!json.extends) {
return json;
}
const extendsFromRoot = `${utils_1.offsetFromRoot(tree.root.path)}tslint.json`;
if (Array.isArray(json.extends) && json.extends.length) {
json.extends = json.extends.filter((ext) => ext !== extendsFromRoot);
}
if (typeof json.extends === 'string' && json.extends === extendsFromRoot) {
delete json.extends;
}
return json;
});
}
function convertRootTSLintConfig(rootTslintJsonPath, rootEslintrcJsonPath) {

@@ -124,3 +47,3 @@ return async (tree, context) => {

return schematics_1.chain([
ensureESLintPluginsAreInstalled(convertedRoot.ensureESLintPlugins),
utils_2.ensureESLintPluginsAreInstalled(convertedRoot.ensureESLintPlugins),
utils_1.updateJsonInTree(rootEslintrcJsonPath, () => {

@@ -133,5 +56,9 @@ /**

delete eslintPluginConfigRecommended.rules['@angular-eslint/component-selector'];
updateArrPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'plugins', true);
updateArrPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'plugins', true);
updateArrPropAndRemoveDuplication(convertedRootESLintConfig, {
/**
* To avoid users' configs being bigger and more verbose than necessary, we perform some
* deduplication against our underlying recommended configuration that they will extend from.
*/
utils_2.updateArrPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'plugins', true);
utils_2.updateArrPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'plugins', true);
utils_2.updateArrPropAndRemoveDuplication(convertedRootESLintConfig, {
plugins: [

@@ -143,3 +70,3 @@ '@angular-eslint/eslint-plugin',

}, 'plugins', true);
updateArrPropAndRemoveDuplication(convertedRootESLintConfig, {
utils_2.updateArrPropAndRemoveDuplication(convertedRootESLintConfig, {
/**

@@ -164,3 +91,3 @@ * For now, extending from these is too different to what the CLI ships with today, so

*
* // FORMATTING!
* // FORMATTING! Please use prettier y'all!
* "import-spacing": true

@@ -174,3 +101,3 @@ *

*
* // FORMATTING!
* // FORMATTING! Please use prettier y'all!
* "whitespace": [

@@ -204,3 +131,3 @@ * true,

*/
// "spaced-comment": [
// WAS -> "spaced-comment": [
// "error",

@@ -213,8 +140,8 @@ // "always",

delete convertedRootESLintConfig.rules['spaced-comment'];
// "jsdoc/check-indentation": "error",
// WAS -> "jsdoc/check-indentation": "error",
delete convertedRootESLintConfig.rules['jsdoc/check-indentation'];
/**
* We want to use these ones differently (with different rule config) to
* how they were converted, so they wouldn't be cleaned up by our deduplication logic
* and we have to manually remove them.
* We want to use these ones differently (with different rule config) to how they
* are converted. Because they exist with different config, they wouldn't be cleaned
* up by our deduplication logic and we have to manually remove them.
*/

@@ -226,10 +153,17 @@ delete convertedRootESLintConfig.rules['@typescript-eslint/quotes'];

* cause the deduplication logic not to find a match can be addressed via PRs to the recommended
* config in the plugin
* config in the plugin.
*/
delete convertedRootESLintConfig.rules['no-console'];
}
updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'rules', false);
updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'rules', false);
updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'env', true);
updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'env', true);
utils_2.updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'rules', false);
utils_2.updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'rules', false);
utils_2.updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigBase, 'env', true);
utils_2.updateObjPropAndRemoveDuplication(convertedRootESLintConfig, eslintPluginConfigRecommended, 'env', true);
/**
* Templates and source code require different ESLint config (parsers, plugins etc), so it is
* critical that we leverage the "overrides" capability in ESLint.
*
* We therefore need to split out rules which are intended for Angular Templates and apply them
* in a dedicated config block which targets HTML files.
*/
const convertedRules = convertedRootESLintConfig.rules || {};

@@ -246,3 +180,3 @@ const templateRules = {};

});
updateObjPropAndRemoveDuplication({ rules: templateRules }, eslintPluginTemplateConfigRecommended, 'rules', false);
utils_2.updateObjPropAndRemoveDuplication({ rules: templateRules }, eslintPluginTemplateConfigRecommended, 'rules', false);
convertedRootESLintConfig.root = true;

@@ -285,3 +219,3 @@ convertedRootESLintConfig.overrides = [

delete convertedRootESLintConfig.parserOptions;
// All applied in the .ts overrides block
// All applied in the .ts overrides block so should no longer be at the root fo the config
delete convertedRootESLintConfig.rules;

@@ -295,57 +229,1 @@ delete convertedRootESLintConfig.plugins;

}
function updateArrPropAndRemoveDuplication(json, configBeingExtended, arrPropName, deleteIfUltimatelyEmpty) {
json[arrPropName] = json[arrPropName] || [];
configBeingExtended[arrPropName] = configBeingExtended[arrPropName] || [];
json[arrPropName] = json[arrPropName].filter((extended) => !configBeingExtended[arrPropName].includes(extended));
json[arrPropName] = Array.from(new Set(json[arrPropName]));
if (deleteIfUltimatelyEmpty && json[arrPropName].length === 0) {
delete json[arrPropName];
}
}
exports.updateArrPropAndRemoveDuplication = updateArrPropAndRemoveDuplication;
function updateObjPropAndRemoveDuplication(json, configBeingExtended, objPropName, deleteIfUltimatelyEmpty) {
json[objPropName] = json[objPropName] || {};
configBeingExtended[objPropName] = configBeingExtended[objPropName] || {};
for (const [name, val] of Object.entries(json[objPropName])) {
const valueOfSamePropInExtendedConfig = configBeingExtended[objPropName][name];
try {
assert.deepStrictEqual(val, valueOfSamePropInExtendedConfig);
delete json[objPropName][name];
}
catch (_a) { }
}
if (deleteIfUltimatelyEmpty && Object.keys(json[objPropName]).length === 0) {
delete json[objPropName];
}
}
exports.updateObjPropAndRemoveDuplication = updateObjPropAndRemoveDuplication;
function ensureESLintPluginsAreInstalled(eslintPluginsToBeInstalled) {
return (host, context) => {
var _a;
if (!(eslintPluginsToBeInstalled === null || eslintPluginsToBeInstalled === void 0 ? void 0 : eslintPluginsToBeInstalled.length)) {
return;
}
if (!host.exists('package.json')) {
throw new Error('Could not find a `package.json` file at the root of your workspace');
}
const projectPackageJSON = host.read('package.json').toString('utf-8');
const json = JSON.parse(projectPackageJSON);
json.devDependencies = json.devDependencies || {};
const pluginsToInstall = [];
for (const pluginName of eslintPluginsToBeInstalled) {
if (!json.devDependencies[pluginName] &&
!((_a = json.dependencies) === null || _a === void 0 ? void 0 : _a[pluginName])) {
json.devDependencies[pluginName] = 'latest';
pluginsToInstall.push(pluginName);
}
}
if (pluginsToInstall.length > 0) {
context.logger.info('\nTo most closely match your tslint.json, the `latest` version of following eslint plugins have been installed:');
context.logger.warn('\n - ' + pluginsToInstall.join('\n - '));
context.logger.warn('\nNOTE: You may wish to pin these to a specific version number in your package.json, rather than leaving it open to `latest`.\n');
host.overwrite('package.json', JSON.stringify(json, null, 2));
context.addTask(new tasks_1.NodePackageInstallTask());
}
return host;
};
}
{
"name": "@angular-eslint/schematics",
"version": "0.7.0-alpha.9",
"version": "0.7.0-alpha.10",
"description": "Angular Schematics for angular-eslint",

@@ -27,3 +27,3 @@ "license": "MIT",

"strip-json-comments": "3.1.1",
"tslint-to-eslint-config": "2.0.0-beta1"
"tslint-to-eslint-config": "2.0.0-beta2"
},

@@ -41,3 +41,3 @@ "devDependencies": {

},
"gitHead": "635ed52da0cd8c50545e7513c2bfc78421e298e7"
"gitHead": "ea51b882882edfc5e1a740fa81a7da34cffe0f84"
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc