I don't know if this bug is more related to react-scripts than to tslint. :/
Linting does not group imports on react-scripts: 3.0.0.
Files from src seem to be considered as librairies
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Navbar from 'components/Navbar';
import Dashboard from 'pages/Dashboard';
import NoMatch from 'pages/NoMatch';
import Settings from 'pages/Settings';
tslint.json configuration:{
"defaultSeverity": "error",
"extends": [
"tslint:recommended",
"tslint-react",
"tslint-config-prettier"
],
"jsRules": {},
"rules": {
"quotemark": false,
"object-literal-sort-keys": false,
"ordered-imports": [
true,
{
"grouped-imports": true
}
],
"interface-name": false,
"jsx-boolean-value": false,
"jsx-equals-spacing": false,
"jsx-no-bind": true,
"jsx-no-lambda": true,
"jsx-self-close": true,
"no-relative-imports": true,
"no-var-requires": false,
"member-ordering": false,
"no-any": true
},
"linterOptions": {
"exclude": [
"*.json",
"**/*.json"
]
},
"rulesDirectory": [
"node_modules/tslint-microsoft-contrib"
]
}
tsconfig.json configuration:React-scripts asks for baseUrl to be set to src OR node_modules.
Would this be what causes tslint to behave wrongly ?
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"baseUrl": "src"
},
"include": [
"src"
]
}
import Navbar from 'components/Navbar';
import Dashboard from 'pages/Dashboard';
import NoMatch from 'pages/NoMatch';
import Settings from 'pages/Settings';
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import React, { Component } from 'react';
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import Navbar from 'components/Navbar';
import Dashboard from 'pages/Dashboard';
import NoMatch from 'pages/NoMatch';
import Settings from 'pages/Settings';
Looks essentially the same as #3654. I don't think ordered-imports looks at tsconfig path mapping or baseUrl.
IMO this kind of pattern is still pretty awkward and confusing to me as a code reader (same as https://github.com/palantir/tslint/issues/3654#issuecomment-358027681). There's no indication of whether "components/**" is importing from an NPM package or from a local source file.
@adidahiya I usually prefer the src/* (from "src/components/File", from "src/App") path style but I guess i can't accomplish this reading because of react-scripts forcing baseUrl as "src" (and not ".").
"paths" are not supported by react-scripts as of right now
I have the same issue in react project (create-react-app 3). Do you have some news ?
Paths seems to be fix but what about _baseurl_ ts compiler options ?
Thanks for infos.
TSLint is deprecated and no longer accepting pull requests other than security fixes. See #4534. โ ๏ธ
We recommend you instead use typescript-eslint to lint your TypeScript code with ESLint. โ
๐ It was a pleasure open sourcing with you!
๐ค Beep boop! ๐ TSLint is deprecated ๐ _(#4534)_ and you should switch to typescript-eslint! ๐ค
๐ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐