Activate the TSlint rule for organizing imports by module source path

Configuring my TSLint rules has been a challenge for me, especially when it comes to including ordered-imports with module-source-path. I aim to establish rules where imports are organized primarily by path and then by sources with distinct groups (1st group = external libraries, 2nd group = internal sources). It is crucial for me to have an auto-fix feature as well.

Here is an example of correctly sorted imports:

import { CommonModule } from '@angular/common';
import { Observable } from 'rxjs';

import { MainComponent } from 'app/components/main.component';
import { MainService } from 'app/services/main.service';

I made the following addition to my tslint.json:

"ordered-imports": [
        true,
        {
            "import-sources-order": "any",
            "named-imports-order": "case-insensitive",
            "grouped-imports": true,
            "module-source-path": "full"
        }
    ],

However, WebStorm gives me an error or warning on the lines "grouped-imports": true, and "module-source-path": "full", stating that "Property 'X' is not allowed" (where X represents one of these options). Despite the documentation indicating that it is feasible to add them here.

Interestingly, there are only 3 out of 4 available options for this rule on GitHub.

My tools are: TSLint 5.11.0 and WebStorm 2018.2.2.

Have I missed something in the configuration? Is there another approach to implement these rules effectively?

EDIT: In addition to the warnings, it seems that these two rules do not function at all - the linter does not flag errors with imports like this:

import { MainService } from 'app/services/main.service';
import { MainComponent } from 'app/components/main.component';

Answer №1

Although the options are valid, the issue lies in the fact that the bundled tslint JSON schema file is not up to date. This has been reported and logged under WEB-56782. Please keep an eye on this link for any updates. In the meantime, I recommend temporarily disabling the Compliance with JSON schema inspection in Settings | Editor | InspectionsJSON and JSON5 to eliminate these errors.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the capabilities of Vitest by testing a RESTful API in SvelteKit

I am looking to create unit tests for a REST API built with SvelteKit, but most of the available resources focus on testing svelte components. Additionally, I prefer to avoid using Playwright as I do not require browser testing and want to steer clear of d ...

Error: The module 'fs' could not be located after running Rollup

Having encountered this issue, I understand that it has been a common question on the internet. I apologize for potentially duplicating the query. Despite trying various solutions found online, none have proven to be effective. The Problem: The problem ar ...

Turning Typescript into Javascript - the How-To Guide

Currently following Shopify's Node Api tutorial to implement a Redis store in my project. The tutorial provides code in typescript, but my entire project is in javascript (React/nextjs). I've been struggling to convert the code to javascript for ...

Optimal approach to configuring Spring Boot and Angular for seamless communication with Facebook Marketing API

Currently, I am working on a Spring Boot backend application and incorporating the Facebook marketing SDK. For the frontend, I am utilizing Angular 10. Whenever I create a new page or campaign, my goal is to send the corresponding object back to the fronte ...

Obtain the roster of channels on Discord version 14

I'm struggling to retrieve the channels list of my guild using discord14 API In my previous code (discord13), I was successfully able to fetch them with this snippet const guild = bot.guilds.cache.get(GUILD_ID) const channels2 = guild.channels.c ...

Merge two arrays by matching their corresponding identifiers

I have 2 separate arrays that I need to merge. The first array looks like this: const Dogs[] = [ { id: '1', name: 'Buddy' }, { id: '2', name: 'Max' }, ] The second one: const dogAges[] = [ { id: '4&ap ...

typescript unconventional syntax for object types

As I was going through the TypeScript handbook, I stumbled upon this example: interface Shape { color: string; } interface Square extends Shape { sideLength: number; } var square = <Square>{}; square.color = "blue"; square.sideLength = 10; ...

Array containing multiple service providers in Angular

I encountered a problem while utilizing multiple providers in my application: ERROR Error: No provider for Array! at injectionError (VM634 core.umd.js:1238) [angular] at noProviderError (VM634 core.umd.js:1276) [angular] at ReflectiveInjector_._throwOrNul ...

ANGULAR - Creating Specific Query Parameters When Navigating Backwards

Is there a way to automatically include query parameters when navigating back to the previous page using the browser's default back button? For instance, when calling a customer-hierarchy component view, you can add query parameters like this: <a ...

Error: Observable<any> cannot be converted to type Observable<number> due to a piping issue

What causes the type error to be thrown when using interval(500) in the code snippet below? const source = timer(0, 5000); const example = source.pipe(switchMap(() => interval(500))); const subscribe = example.subscribe(val => console.log(val)); V ...

What is the best way to selectively pass certain values to the args object?

Is there a way in TypeScript to pass only one argument into args and have other values be default without using "args = {}" or declaring defaults within the function to avoid issues with intellisense? function generateBrickPattern ( wallWidth: number, ...

Enhancing Security and Privacy of User Information with JWT Tokens and NgRx Integration in Angular Application

I'm facing a security concern with my Angular application. Currently, I store user details like isAdmin, isLoggedIn, email, and more in local storage. However, I'm worried about the risks of unauthorized updates to this data, especially since my ...

The TypeScript library React-Time-Ago seems to require a number, but I'm passing it a string instead. I'm struggling to find a way to make it accept a number

import ReactTimeAgo from "react-time-ago" <ReactTimeAgo date = {tweet._createdAt} /> _createdAt displays time in the format 2022-06-02T01:16:40Z To convert this into a more human-readable form like " ...

Jest identifies active handles when executing synchronous scrypt operations in the crypto module of Node.js

During the execution of a unit test using the scryptSync function from the crypto package, I am encountering error messages and warnings that are unfamiliar to me. For instance, here is an example of a unit test I am running in Jest: it('Should match ...

Troubleshooting Typescript compilation using tsc with a locally linked node package

In our project using React/React Native with Typescript, we have a mobile app built with React Native and a shared private package that is utilized by both the React Native client and the React frontend. Due to frequent changes in the shared package, we a ...

What is the best way to connect input values with ngFor and ngModel?

I am facing an issue with binding input values to a component in Angular. I have used ngFor on multiple inputs, but the input fields are not showing up, so I am unable to push the data to subQuestionsAnswertext. Here is the code snippet from app.component ...

Exploring the Power of Observables in Angular 2: Leveraging the Versatility of

As a student working on developing a simple WebApp and Server, I have encountered some issues with Http.post and Http.get methods using Observables. My main challenge is related to posting a boolean value to the server when a button is pressed. While the ...

What is the reason for the failure of this typescript typeguard?

This code snippet defines a function for validating protocols and throwing an error if the input does not match the predefined protocols. const validProtocols = ["https", "http"] as const type AllProtocols = typeof validProtocols type Protocol = AllProtoco ...

Ts2532, The existence of the object is potentially unsafe

I am encountering an issue while trying to update a task in my project built with the MEAN stack. Although all APIs are functioning properly, I am facing an error when attempting to patch an element using the ID parameter. The error message displayed is: & ...

Changing the color of an Angular <div> element with scripting

I am currently working on an Angular 6 project and I need to change the colors of a div tag from a script after a click function. However, I also need to change it back to transparent. When I click on the "Inheritance" option, the background color of the ...