Skip to content

Commit

Permalink
Add eslint rule to enforce file extenstions (#1008)
Browse files Browse the repository at this point in the history
Reference to the coding_convention - https://github.com/DEFRA/water-abstraction-team/blob/main/coding_conventions.md#add-the-js-extension

When linking to an internal module in our require() statements always include the *.js extension.

// Good
const RequestLib = require('../lib/request.lib.js')

// Bad
const RequestLib = require('../lib/request.lib')

We know 😝 that you don't have to and that generally the convention is not to. But we still hold out hope that one day we'll switch our main repo from CommonJS to ES6 modules. The extension is required when using import and the work of migrating is made easier if the existing require() statements already include it.
  • Loading branch information
jonathangoulding authored May 13, 2024
1 parent 06d93ba commit 6ee704a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
ignoreStrings: true,
ignoreTemplateLiterals: true,
ignoreUrls: true
}]
}],
'import/extensions': ['error', 'always']
}
}

Expand Down

0 comments on commit 6ee704a

Please sign in to comment.