Skip to content

different lang with different rules #1523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Airkro opened this issue Jun 25, 2021 · 5 comments
Closed

different lang with different rules #1523

Airkro opened this issue Jun 25, 2021 · 5 comments

Comments

@Airkro
Copy link

Airkro commented Jun 25, 2021

Tell us about your environment

  • ESLint version: 7.29
  • eslint-plugin-vue version: 7.12.0
  • Node version: 14.17.0

The problem you want to solve.

<!-- use different rule -->
<script lang="js"></script>
<script lang="ts"></script>

Your take on the correct solution to problem.

// .eslintrc.js
module.export = {
  parser: 'vue-eslint-parser',
  overrides: [
    {
      files: '*.vue/**/*.ts',
      parserOptions: {
        parser: '@typescript-eslint/parser',
      },
    },
    {
      files: '*.vue/**/*.js',
      parserOptions: {
        parser: '@babel/eslint-parser',
      },
      rule: {
        'no-unused-vars': 'warn',
      }
    }
  ]
};

Additional context

Something like:
https://github.com/eslint/eslint-plugin-markdown#advanced-configuration

@ota-meshi
Copy link
Member

Thank you for posting this issue.
But, this plugin cannot be configured separately for lang due to its mechanism.
Thank you for your understanding.

@Airkro
Copy link
Author

Airkro commented Jul 8, 2021

vuejs/vue-eslint-parser#116

It's possible, right?

@adamxi
Copy link

adamxi commented Jul 8, 2021

@Airkro: I think I got it all working doing this:

	parser: "vue-eslint-parser",
	parserOptions: {
		parser: {
			// Script parser for `<script>`
			js: false,

			// Script parser for `<script lang="ts">`
			ts: "@typescript-eslint/parser",

			// Script parser for vue directives (e.g. `v-if=` or `:attribute=`) and vue interpolations (e.g. `{{variable}}`).
			// If not specified, the parser determined by `<script lang ="...">` is used.
			"<template>": false,
		},
	},

I also had to an install of the typescript linter:
npm i --save-dev typescript @typescript-eslint/parser

@ota-meshi
Copy link
Member

Rules cannot be configured by lang.

@lovetingyuan
Copy link

Rules cannot be configured by lang.

Why not use 'processor.preprocess' ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants