Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop replacing relative path to absolute path all files automatically

My problems is when I was coding the editor of vscode auto replace from relative path to absolute path of all files in my project automatically.

For example: When I import like this:

import { login } from '../logic.redux/action'

Five minutes latter(maybe some actions like save or import another file) it will convert to:

import { login } from '@module/login/logic.redux/action'

And seriously it's override all files to absolute files. Tell me what am I doing wrong

My project include : Typescript + react-native(project)

Here is my tsconfig.json

{
	"compilerOptions": {
		"module": "es6",
		"target": "es6",
		"lib": ["es6", "dom"],
		"sourceMap": true,
		"allowJs": true,
		"allowSyntheticDefaultImports": true,
		"esModuleInterop": true,
		"jsx": "react-native",
		"moduleResolution": "node",
		"noEmit": true,
		"experimentalDecorators": true,
		"forceConsistentCasingInFileNames": true,
		"noImplicitReturns": true,
		"noImplicitThis": true,
		"noImplicitAny": true,
		"strictNullChecks": true,
		"suppressImplicitAnyIndexErrors": true,
		"noUnusedLocals": false,
		"baseUrl": "./src",
		"paths": {
			"@conf/*": ["./conf/*"],
			"@i18n/*": ["./i18n/*"],
			"@module/*": ["./module/*"],
			"@router/*": ["./router/*"],
			"@theme/*": ["./theme/*"],
			"@tpl/*": ["./tpl/*"],
			"@util/*": ["./util/*"]
		}
		
	},
	"exclude": ["node_modules"]
}

And here is my tslint.json

{
	"defaultSeverity": "error",
	"extends": [
		"tslint-config-airbnb"
	],
	"jsRules": {},
	"rules": {
		"indent": [
			true,
			"tabs", 4
		],
		"ter-indent": [
			false
		],
		"semicolon": [
			true,
			"never"
		],
		"object-literal-sort-keys": false,
		"quotemark": [
			true,
			"single",
			"jsx-double"
		],
		"ordered-imports": true,
		"interface-name": [
			false
		],
		"max-line-length": [
			true,
			140
		],
		"no-console": [
			false
		],
		"no-empty-interface": false,
		"no-var-requires": false,
		"import-name": false,
		"no-consecutive-blank-lines": [
			true,
			0
		],
		"no-increment-decrement": false,
		"variable-name": [
			true,
			"ban-keywords",
			"check-format",
			"allow-pascal-case"
		],
		"no-unused-variable": false
	},
	"rulesDirectory": []
}

And user setting in vscode

{
    "workbench.colorTheme": "Bimbo Theme",
    "sublimeTextKeymap.promptV3Features": true,
    "editor.renderWhitespace": "boundary",
    "editor.rulers": [100],
    "editor.cursorBlinking": "solid",
    "editor.fontFamily": "Fira Code",
    "editor.fontLigatures": true,
    "window.zoomLevel": 0,
    "todohighlight.isEnable": true,
    "javascript.implicitProjectConfig.experimentalDecorators": true,
    "gitlens.advanced.messages": {
        "suppressShowKeyBindingsNotice": true
    },
    "files.autoSave": "off",
    "eslint.autoFixOnSave":true,
    "tslint.autoFixOnSave": true,
    "tslint.configFile": "./tslint.ide.json",
    "typescript.updateImportsOnFileMove.enabled": "always",
    "javascript.implicitProjectConfig.experimentalDecorators": true,
    "editor.detectIndentation": false,
    "editor.insertSpaces": false,
	"editor.tabSize": 4,

}

And here is List extension of

PeterJausovec.vscode-docker
abotteram.typescript-react-snippets
ajhyndman.jslint
anseki.vscode-color
azemoh.one-monokai
bierner.markdown-preview-github-styles
chenxsan.vscode-standardjs
chong.vscode-typescript-react-redux-snippets
christian-kohler.path-intellisense
cmstead.jsrefactor
Compulim.compulim-vscode-closetag
cssho.vscode-svgviewer
Dart-Code.dart-code
dbaeumer.vscode-eslint
DotJoshJohnson.xml
dracula-theme.theme-dracula
dsznajder.es7-react-js-snippets
eamodio.gitlens
EditorConfig.EditorConfig
eg2.tslint
emmanuelbeziat.vscode-great-icons
esbenp.prettier-vscode
formulahendry.auto-close-tag
formulahendry.auto-complete-tag
formulahendry.auto-rename-tag
HookyQR.beautify
infeng.vscode-react-typescript
jundat95.react-native-snippet
karyfoundation.comment
kevinkyang.auto-comment-blocks
mgmcdermott.vscode-language-babel
miclo.sort-typescript-imports
mohsen1.prettify-json
monokai.theme-monokai-pro-vscode
ms-python.python
ms-vscode.node-debug2
ms-vscode.sublime-keybindings
naumovs.color-highlight
patrys.vscode-code-outline
pawelgrzybek.bimbo-theme
pmneo.tsimporter
pnp.polacode
richie5um2.vscode-sort-json
santosh.react-native-snippet
shd101wyy.markdown-preview-enhanced
stevencl.addDocComments
teabyii.ayu
vsmobile.vscode-react-native
waderyan.gitblame
wayou.vscode-todo-highlight
wix.vscode-import-cost
xabikos.JavaScriptSnippets
yzhang.markdown-all-in-one
zengxingxin.sort-js-object-keys
like image 658
Tri Tom V LE Avatar asked Jul 12 '18 04:07

Tri Tom V LE


2 Answers

Open vscode user settings: File -> Preferences -> Settings

set "javascript.updateImportsOnFileMove.enabled": "prompt",

prompt on each rename
always update paths automatically
never rename paths and don't prompt me

yours are probably set on always

like image 199
hadifikri Avatar answered Oct 10 '22 02:10

hadifikri


Try to reinstall vscode. And select 'no and never' button when you change name file it will show the pop up look like this "Automatically update imports for moved file"

https://github.com/Microsoft/vscode/issues/53832

like image 25
Le Tom Avatar answered Oct 10 '22 03:10

Le Tom