hparra / gulp-rename

Rename files easily
MIT License
692 stars 73 forks source link

Rename via function. Return object instead of reassign. #85

Closed evanre closed 4 years ago

evanre commented 5 years ago

Hi, I'm trying to rename files using the change-case module. But the eslint shows me an error no-param-reassign. Isn't it better to return the object instead of reassigning its properties? Replace this:

.pipe(rename((path) => {
    path.basename = changeCase.paramCase(path.basename);
}))

to this:

.pipe(rename((path) => {
    const basename = changeCase.paramCase(path.basename);
    return {...path, basename};
}))

or even this:

.pipe(rename(path => ({ ...path, basename: changeCase.paramCase(path.basename) })))
yocontra commented 5 years ago

@evanre I agree that making the object immutable would be a better API, but I think supporting both cases would make the most sense. If an object is returned, use that - otherwise use the object passed in. This is mainly to make things easier for people who aren't using ES7 for their gulpfiles and still using node supported syntax where cloning can be really annoying via Object.assign.

If you want to send a PR that would be helpful - otherwise I might get around to it in the coming weeks.