-
Notifications
You must be signed in to change notification settings - Fork 129
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
support absolute path imports as local imports (ts/jsconfig.json) #162
Comments
Could this help? const packages = require('./package.json').dependencies;
const sortedPackages = Object.keys(packages).sort();
module.exports = {
printWidth: 120,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
endOfLine: 'lf',
// any order specification. for example. styles last \./\S+\.\w+ss
importOrder: sortedPackages.concat(['<THIRD_PARTY_MODULES>', '^\\.\\./', '^\\./']),
importOrderSeparation: true,
importOrderSortSpecifiers: true,
importOrderCaseInsensitive: true,
}; Actually |
Thanks for the inspo, @tearf001! Since I didn't want const { readdirSync } = require('fs');
const { baseUrl } = require('./tsconfig.json').compilerOptions;
const baseUrlSubdirectories = readdirSync(`${__dirname}/${baseUrl}`, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name);
const baseUrlSubdirectoryRegex = `^(${baseUrlSubdirectories.join('|')})`;
module.exports = {
$schema: 'http://json.schemastore.org/prettierrc',
arrowParens: 'always',
bracketSpacing: true,
bracketSameLine: false,
jsxSingleQuote: false,
printWidth: 100,
proseWrap: 'always',
quoteProps: 'as-needed',
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: 'es5',
useTabs: false,
importOrder: [baseUrlSubdirectoryRegex, '^.?[./]'],
importOrderSeparation: true,
}; This will group any import listed as a dependency or devDependency (test imports is what I'm thinking here) at the top of the file, followed by another group of all of my "absoluteish" imports (as dictated by my tsconfig's baseUrl directory), followed by any relative ( |
Thanks @curtvict for sharing your solution, it works like a charm. As our code has some files at the baseUrl-level, e.g. Complete prettierrc.js file:
or even shorter (we went with the more explicit version above)
|
This doesn't solve for other formats like YAML and JSON. |
The above solutions are not working for us, our local imports are treated as if they were third party imports and put in that group instead of the bottom. |
Your Environment
Describe the bug
When using a jsconfig.json or tsconfig.json file to allow absolute path imports, these are treated as third party imports and no longer grouped with local imports. Theses are clearly local imports so should not be grouped in the 3 party section
To Reproduce
Expected behavior
the imported files would be sorted in order with:
(2 and 3 may be combined)
Screenshots, code sample, etc
example folder structure:
jsconfig.json
page.js
Theses are clearly local imports so should not be grouped in the 3 party section
Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)
.prettierrc
Contribute to @trivago/prettier-plugin-sort-imports
The text was updated successfully, but these errors were encountered: