Skip to content
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

Add support for TypeScript configuration files #4940

Closed
jesusbotella opened this issue Sep 14, 2020 · 9 comments
Closed

Add support for TypeScript configuration files #4940

jesusbotella opened this issue Sep 14, 2020 · 9 comments
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules

Comments

@jesusbotella
Copy link

What is the problem you're trying to solve?

As many projects are adopting TypeScript as their main language, I think it would be great to have TypeScript support for stylelint configuration file.

That way, developers will be able to import TypeScript files across their codebases to customize rules in stylelint.

What solution would you like to see?

An option to have a TypeScript file as a valid configuration file along with JavaScript configuration files.

I saw that stylelint uses cosmiconfig for importing configuration files and there's a TypeScript file loader for that. So I can open up a PR if you think that TS configuration files are useful for stylelint users.

@jeddy3
Copy link
Member

jeddy3 commented Sep 15, 2020

@jesusbotella Thanks for the request and for using the template.

Sounds good to me.

there's a TypeScript file loader for that.

For those interested, here's the cosmiconfig loader.

Unless anyone has an objection, I'll label as good to go?

@jeddy3 jeddy3 added the status: needs discussion triage needs further discussion label Sep 15, 2020
@jeddy3 jeddy3 changed the title TypeScript support for configuration file Add support for TypeScript configuration files Sep 15, 2020
@jesusbotella
Copy link
Author

Thank you!

Just in case anyone wants to know what it takes to add the TypeScript loader, here is the implementation that I have been testing in my project: jesusbotella@06af34b

@jeddy3
Copy link
Member

jeddy3 commented Sep 16, 2020

As we have three thumbs-up already, I'll label as ready to implement.

Please consider contributing the enhancement if you have time.

@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules and removed status: needs discussion triage needs further discussion labels Sep 16, 2020
@hudochenkov
Copy link
Member

Just for information ESLint declined idea to support .eslintrc.ts eslint/rfcs#50

@ybiquitous
Copy link
Member

@hudochenkov Thank you for sharing the valuable thread! After I read the thread, I started wondering if we really need to support the TypeScript configuration file format. 🤔

In addtion, peerDependencies will be installed automatically since npm v7, so my suggestion using peerDependenciesMeta in the PR #4947 may not be effective... 😕

Sorry to the PR author, but shouldn't we rethink this issue?

@jesusbotella
Copy link
Author

Yeah, I've read the reasons why ESLint project didn't want to support it and seem reasonable. Installing Typescript in every project that uses stylelint is not a good solution.

My point was that the number of projects that use TypeScript nowadays is growing, and their developers might want to include dynamic configuration for stylelint rules, as I do, to use plugins like stylelint-scales or other use cases.

The proposal of having configuration plugins is good, but stylelint doesn't have a way to do that yet, and it might not be worth just to add support for TypeScript configuration files.

What do you think?

@jesusbotella
Copy link
Author

I have an update regarding TypeScript support in configuration files. While stylelint might not support them (and I think it's the right thing to do), developers can import TypeScript files with ts-node (tsconfig-paths might be needed too) within stylelint.config.js.

Developers can import ts-node at the top of the file, and ts-lint will register .ts extension in node resolvers. That way, .ts files will be transpiled with TypeScript first, and Node will import them without issues. I'll include an example below.

I think we can close the pull request that I opened, and leave this snippet here so that anyone can import TypeScript files in their stylelint configuration.

stylelint.config.js

require('ts-node/register');

const dynamicStylelintRules = require('./myTypeScriptFile');

module.exports = {
  ...dynamicStylelintRules
}

@ybiquitous
Copy link
Member

@jesusbotella Thank you for providing the snippet.

I agree with closing PR #4947 if we cannot resolve the problem of increasing extra dependencies.

@jeddy3
Copy link
Member

jeddy3 commented Nov 1, 2020

Thanks for the update (#4940 (comment)). I'll close this issue and the pull request.

@jeddy3 jeddy3 closed this as completed Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone type: enhancement a new feature that isn't related to rules
Development

Successfully merging a pull request may close this issue.

4 participants