zcuric / eslint-plugin-require-sort Goto Github PK
View Code? Open in Web Editor NEWESlint plugin for sorting requires (CommonJS modules) alphabetically
License: MIT License
ESlint plugin for sorting requires (CommonJS modules) alphabetically
License: MIT License
I was trying to apply the rule to a file that contains the following require:
const { mongoPort, ...ports } = require('app/ports')
But for some reason, the rule was throwing this error (I removed the full path for privacy purposes):
TypeError: Cannot read property 'name' of undefined
Occurred while linting /Path/to/file/index.js:1
at getSortableName (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:179:75)
at Array.map (<anonymous>)
at handlePropertySort (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:107:47)
at Array.forEach (<anonymous>)
at ProgramExit (/Path/to/file/node_modules/eslint-plugin-require-sort/dist/index.js:252:44)
at /Path/to/file/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Path/to/file/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Path/to/file/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
at NodeEvent
But when I changed the code to the following line, it worked and the error stopped:
const ports = require('app/ports')
const { mongoPort } = ports
Is this error intended, or is it a bug?
The plugin shows error while requiring objects starting in capital letters(non-exhaustive case).
index.js:
const debug = require('debug')('eslint-plugin-require-sort_issue-test:index');
const express = require('express');
const Function1 = require('./a');
const app = express();
const port = 3000;
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(port, function () {
debug(`Example app listening on port ${port}!`);
});
Function1();
a.js:
const debug = require('debug')('eslint-plugin-require-sort_issue-test:a');
const a = function () {
debug('I am the mighty A.');
};
module.exports = a;
Eslint Error:
Requires should be sorted alphabetically : index.js:3:1
Hi, thanks for this plugin!
I've started experimenting a bit with it and I've found out that it seems to ignore require statements that are using nested object destructuring.
Check this example:
const {C: {nestedProperty}} = require('./c.js');
const {A} = require('./a.js');
const {B} = require('./b.js');
const a = new A();
const b = new B();
const c = new nestedProperty();
It doesn't really matter where you put the line with nestedProperty
, ESLint do not throw any errors. Hence I'm wondering if this might be an issue or just the expected behaviour.
I would expect it to complain cause nestedProperty
is using small caps for the first letter, so it should be placed after {B}
.
I'm using default config with 'require-sort/require-sort': 'error'
in my .eslintrc.js
file.
Thanks again.
Title.
Hey,
Thanks for the OSS package!
Wondering if the auto fix is already implemented, per kentor/eslint-plugin-sort-requires#1
Thank you!!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.