Skip to content

Commit

Permalink
Do not allow trailing commas in code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mkacmar committed Oct 1, 2024
1 parent b575f28 commit 5974046
Show file tree
Hide file tree
Showing 48 changed files with 405 additions and 404 deletions.
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"printWidth": 100
"printWidth": 100,
"trailingComma": "none"
}
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ module.exports = [
{
rules: {
"no-eval": "error",
"@microsoft/sdl/no-inner-html": "error",
},
},
"@microsoft/sdl/no-inner-html": "error"
}
}
];
```

Expand Down
8 changes: 4 additions & 4 deletions config/angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ module.exports = (pluginSdl) => {
return [
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"@microsoft/sdl/no-angular-bypass-sanitizer": "error",
},
},
"@microsoft/sdl/no-angular-bypass-sanitizer": "error"
}
}
];
};
8 changes: 4 additions & 4 deletions config/angularjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module.exports = (pluginSdl) => {
return [
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"@microsoft/sdl/no-angularjs-enable-svg": "error",
"@microsoft/sdl/no-angularjs-sanitization-whitelist": "error",
"@microsoft/sdl/no-angularjs-bypass-sce": "error",
},
},
"@microsoft/sdl/no-angularjs-bypass-sce": "error"
}
}
];
};
8 changes: 4 additions & 4 deletions config/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (pluginSdl) => {
return [
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"no-caller": "error",
Expand All @@ -23,8 +23,8 @@ module.exports = (pluginSdl) => {
"@microsoft/sdl/no-insecure-url": "error",
"@microsoft/sdl/no-msapp-exec-unsafe": "error",
"@microsoft/sdl/no-postmessage-star-origin": "error",
"@microsoft/sdl/no-winjs-html-unsafe": "error",
},
},
"@microsoft/sdl/no-winjs-html-unsafe": "error"
}
}
];
};
8 changes: 4 additions & 4 deletions config/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ module.exports = (pluginSdl) => {
return [
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"@microsoft/sdl/no-electron-node-integration": "error",
},
},
"@microsoft/sdl/no-electron-node-integration": "error"
}
}
];
};
14 changes: 7 additions & 7 deletions config/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ module.exports = (pluginSdl) => {
return [
{
plugins: {
n: pluginN,
n: pluginN
},
rules: {
"n/no-deprecated-api": "error",
},
"n/no-deprecated-api": "error"
}
},
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"@microsoft/sdl/no-unsafe-alloc": "error",
},
},
"@microsoft/sdl/no-unsafe-alloc": "error"
}
}
];
};
26 changes: 13 additions & 13 deletions config/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ module.exports = (pluginSdl) => {
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
jsx: true
}
}
}
},
{
plugins: {
react: pluginReact,
react: pluginReact
},
rules: {
"react/no-danger": "error",
Expand All @@ -27,18 +27,18 @@ module.exports = (pluginSdl) => {
{
allowReferrer: false,
enforceDynamicLinks: "always",
warnOnSpreadAttributes: true,
},
],
},
warnOnSpreadAttributes: true
}
]
}
},
{
plugins: {
"@microsoft/sdl": pluginSdl,
"@microsoft/sdl": pluginSdl
},
rules: {
"@microsoft/sdl/react-iframe-missing-sandbox": "error",
},
},
"@microsoft/sdl/react-iframe-missing-sandbox": "error"
}
}
];
};
20 changes: 10 additions & 10 deletions config/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ module.exports = () => {
ecmaVersion: 6,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
},
jsx: true
}
}
}
},
{
files: ["**/*.{ts,tsx}"],
languageOptions: {
parserOptions: {
parser: "@typescript-eslint/parser",
},
parser: "@typescript-eslint/parser"
}
},
plugins: {
"@typescript-eslint": pluginTypescript,
"@typescript-eslint": pluginTypescript
},
rules: {
"@typescript-eslint/no-implied-eval": "error",
// @typescript-eslint/no-implied-eval offers more accurate results for typescript.
// thus we turn the more generic rule off for ts and tsx files.
// This also avoids duplicate hits.
"no-implied-eval": "off",
},
},
"no-implied-eval": "off"
}
}
];
};
2 changes: 1 addition & 1 deletion lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ module.exports = {
);
}
return false;
},
}
};
14 changes: 7 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const pkg = require(path.join("..", "package.json"));
const plugin = {
meta: {
name: pkg.name,
version: pkg.version,
version: pkg.version
},
rules: {
"no-angular-bypass-sanitizer": require("./rules/no-angular-bypass-sanitizer"),
Expand All @@ -31,10 +31,10 @@ const plugin = {
"no-postmessage-star-origin": require("./rules/no-postmessage-star-origin"),
"no-unsafe-alloc": require("./rules/no-unsafe-alloc"),
"no-winjs-html-unsafe": require("./rules/no-winjs-html-unsafe"),
"react-iframe-missing-sandbox": require("./rules/react-iframe-missing-sandbox"),
"react-iframe-missing-sandbox": require("./rules/react-iframe-missing-sandbox")
},
// Filled in later in order to reference plugin itself.
configs: {},
configs: {}
};

plugin.configs["angular"] = require("../config/angular")(plugin);
Expand All @@ -51,17 +51,17 @@ plugin.configs["required"] = [
...plugin.configs["common"],
...plugin.configs["electron"],
...plugin.configs["node"],
...plugin.configs["react"],
...plugin.configs["react"]
];

plugin.configs["recommended"] = [
...plugin.configs["required"],
...plugin.configs["typescript"],
{
plugins: {
security: pluginSecurity,
},
},
security: pluginSecurity
}
}
];

module.exports = plugin;
14 changes: 7 additions & 7 deletions lib/rules/no-angular-bypass-sanitizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ module.exports = {
category: "Security",
description:
"Calls to bypassSecurityTrustHtml, bypassSecurityTrustScript and similar methods bypass DomSanitizer in Angular and need to be reviewed.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-bypass-sanitizer.md",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-bypass-sanitizer.md"
},
messages: {
noBypass: "Do not bypass Angular's built-in sanitizer",
},
noBypass: "Do not bypass Angular's built-in sanitizer"
}
},
create: function (context) {
return {
"CallExpression[arguments!=''][callee.property.name=/bypassSecurityTrust(Html|ResourceUrl|Script|Style|Url)/]"(
node,
node
) {
context.report({
node: node,
messageId: "noBypass",
messageId: "noBypass"
});
},
}
};
},
}
};
14 changes: 7 additions & 7 deletions lib/rules/no-angular-sanitization-trusted-urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ module.exports = {
category: "Security",
description:
"Calls to [`$compileProvider.aHrefSanitizationTrustedUrlList`](https://docs.angularjs.org/api/ng/provider/$compileProvider#aHrefSanitizationTrustedUrlList) configure allowed Url list in AngularJS sanitizer and need to be reviewed.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-sanitization-trusted-urls.md",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angular-sanitization-trusted-urls.md"
},
messages: {
noSanitizationTrustedUrls: "Do not modify the trusted Urls list in AngularJS",
},
noSanitizationTrustedUrls: "Do not modify the trusted Urls list in AngularJS"
}
},
create: function (context) {
return {
"CallExpression[arguments!=''][callee.object.name='$compileProvider'][callee.property.name=/(aHref|imgSrc)SanitizationTrustedUrlList/]"(
node,
node
) {
context.report({
node: node,
messageId: "noSanitizationTrustedUrls",
messageId: "noSanitizationTrustedUrls"
});
},
}
};
},
}
};
16 changes: 8 additions & 8 deletions lib/rules/no-angularjs-bypass-sce.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ module.exports = {
category: "Security",
description:
"Calls to $sceProvider.enabled(false), $sceDelegate.trustAs(), $sce.trustAs() and relevant shorthand methods (e.g. trustAsHtml or trustAsJs) bypass Strict Contextual Escaping (SCE) in AngularJS and need to be reviewed.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angularjs-bypass-sce.md",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angularjs-bypass-sce.md"
},
messages: {
doNotBypass: "Do not bypass Strict Contextual Escaping (SCE) in AngularJS",
},
doNotBypass: "Do not bypass Strict Contextual Escaping (SCE) in AngularJS"
}
},
create: function (context) {
function reportIt(node) {
context.report({
node: node,
messageId: "doNotBypass",
messageId: "doNotBypass"
});
}

return {
"CallExpression[arguments!=''][callee.object.name='$sceProvider'][callee.property.name='enabled']"(
node,
node
) {
// Known false positives
if (
Expand All @@ -48,7 +48,7 @@ module.exports = {
"CallExpression[arguments!=''][callee.object.name='$sceDelegate'][callee.property.name='trustAs']":
reportIt,
"CallExpression[arguments!=''][callee.object.name='$sce'][callee.property.name=/trustAs(Css|Html|Js|ResourceUrl|Url)?/]"(
node,
node
) {
// Known false positives
if (
Expand All @@ -61,9 +61,9 @@ module.exports = {
}

return reportIt(node);
},
}
};
},
}
};

// TODO: Review https://docs.angularjs.org/api/ng/provider/$sceDelegateProvider#resourceUrlWhitelist and https://docs.angularjs.org/api/ng/provider/$sceDelegateProvider#resourceUrlBlacklist
14 changes: 7 additions & 7 deletions lib/rules/no-angularjs-enable-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ module.exports = {
category: "Security",
description:
"Calls to $sanitizeProvider.enableSvg(true) increase attack surface of the application by enabling SVG support in AngularJS sanitizer and need to be reviewed.",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angularjs-enable-svg.md",
url: "https://github.com/microsoft/eslint-plugin-sdl/blob/master/docs/rules/no-angularjs-enable-svg.md"
},
messages: {
doNotEnableSVG: "Do not enable SVG support in AngularJS",
},
doNotEnableSVG: "Do not enable SVG support in AngularJS"
}
},
create: function (context) {
return {
"CallExpression[callee.object.name='$sanitizeProvider'][callee.property.name='enableSvg']"(
node,
node
) {
// Known false positives
if (
Expand All @@ -38,11 +38,11 @@ module.exports = {
}
context.report({
node: node,
messageId: "doNotEnableSVG",
messageId: "doNotEnableSVG"
});
},
}
};
},
}
};

// TODO: Add rules for $sanitizeProvider.addValidElements() and $sanitizeProvider.addValidAttrs()
Loading

0 comments on commit 5974046

Please sign in to comment.