Page MenuHomePhabricator

Use explict .vue extension for Vue imports
Open, Needs TriagePublic

Description

Under vite imports of *.vue files do not work without an explicit extension.

  • Add a linter rule that will error when a *.vue file is imported without an explicit extension. (example)
  • Fix existing imports

Event Timeline

Slst2020 changed the task status from Open to In Progress.Mar 2 2022, 9:39 AM
Slst2020 claimed this task.
Slst2020 added a project: User-Slst2020.
Slst2020 moved this task from To Do to Doing on the User-Slst2020 board.
Slst2020 moved this task from Review to In Progress on the Toolhub board.

Not quite sure how to exclude the helper .js imports from the linter rule

Screenshot 2022-03-02 at 11.50.24.png (274×1 px, 121 KB)

Not quite sure how to exclude the helper .js imports from the linter rule

Screenshot 2022-03-02 at 11.50.24.png (274×1 px, 121 KB)

I haven't tried myself, but I think the upstream config for the rule (https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/extensions.md) implies that it can be tuned by extension.

The config that is working best so far for me is the one resulting in the above behavior:

			{
				"files": [
					"vue/src/**/*.vue"
				],
				"plugins": [
					"import"
				],
				"rules": {
					"import/extensions": [ "error", "ignorePackages", { "vue": "always" } ]
				},
				"settings": {
					"import/resolver": {
						"alias": {
							"map": [
								[
									"@",
									"./src"
								]
							],
							"extensions": [
								".vue",
								".js",
								".json"

							]
						}
					}
				}
			}

On the other hand, configuring the rule as "rules": { "import/extensions": [ "error", { "js": "never", "vue": "always" } ]}, results in all vue imports simply being ignored.

"rules": { "import/extensions": [ "error", "always", { "js": "never" } ]} is even more confusing as it complains about missing .js file extensions EXCEPT for the one import that actually has it, but according to the linter, shouldn't:

Screenshot 2022-03-03 at 12.03.16.png (119×1 px, 44 KB)

Slst2020 changed the task status from In Progress to Open.Mar 3 2022, 11:05 AM
Slst2020 removed Slst2020 as the assignee of this task.
Slst2020 removed a project: User-Slst2020.
Slst2020 subscribed.

Moving this back to "research needed" for now